hanki.dev

Optional chaining rocks?.!

If I had to check if some nested key exists, I used to do something like this:

if(object.child && object.child.second && object.child.second.lol) {...

to avoid null reference errors. But you can do it much cleaner with optional chaining:

if(object.child?.second?.lol) {...

More about optional chaining on MDN

#javascript