Is it good practice to do null checks with optional chaining like the following example?
document.querySelector('.foo')?.classList.add('bar');
In many codebases I see this:
let el = document.querySelector('.foo');
if(el){
el.classList.add('bar');
}
I think chaining is much cleaner and silent failures are happening in both cases. I'm aware of the browser support.