The Elvis operator on a function says "if this exists, call it", just like when you use it to get a property of an object that might be null or undefined.
Just because the operator is unfamiliar to you, doesn't mean it's bad. It just means that it's unfamiliar.
if(typeof myFunction === ‘function’)
Is significantly longer and says exactly the same thing.
Why fight language improvements? Do you disallow spread because you’re used to Object.assign? Or mutate vars inside for loops instead of Array.map? I assure you if you use optional chaining you’ll find it reads far easier especially when accessing deeply nested properties on objects. 4 props or more deep is pretty hideous with &&
It checks if the left hand side is null or undefined and the runs the right hand side.
That's not an apt description of either. I'm not debating function call vs property access. The Elvis operator (?:) and optional chaining are different things.
6
u/recycled_ideas Nov 10 '20
The Elvis operator on a function says "if this exists, call it", just like when you use it to get a property of an object that might be null or undefined.
Just because the operator is unfamiliar to you, doesn't mean it's bad. It just means that it's unfamiliar.
Is significantly longer and says exactly the same thing.
Again, unfamiliar doesn't mean bad.