MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/node/comments/jrau9t/conditionally_call_a_function_with_optional/gbtcq5o
r/node • u/wobsoriano • Nov 10 '20
126 comments sorted by
View all comments
Show parent comments
1
It checks if the left hand side is null or undefined and the runs the right hand side.
There's no difference between a function call and a property access.
1 u/RufusThreepwood Nov 10 '20 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. 1 u/recycled_ideas Nov 10 '20 First off, my apologies, I'd learned ?. as the Elvis operator, I come from a C# background where ?: doesn't exist.That said, my description of optional chaining is accurate.The reason optional chaining works on functions in JavaScript (it doesn't in most languages) is because functions in JavaScript are objects.From the runtimes point of view accessing a property and executing involve evaluating the right hand side in terms of the left.
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.
1 u/recycled_ideas Nov 10 '20 First off, my apologies, I'd learned ?. as the Elvis operator, I come from a C# background where ?: doesn't exist.That said, my description of optional chaining is accurate.The reason optional chaining works on functions in JavaScript (it doesn't in most languages) is because functions in JavaScript are objects.From the runtimes point of view accessing a property and executing involve evaluating the right hand side in terms of the left.
First off, my apologies, I'd learned ?. as the Elvis operator, I come from a C# background where ?: doesn't exist.
That said, my description of optional chaining is accurate.
The reason optional chaining works on functions in JavaScript (it doesn't in most languages) is because functions in JavaScript are objects.
From the runtimes point of view accessing a property and executing involve evaluating the right hand side in terms of the left.
1
u/recycled_ideas Nov 10 '20
It checks if the left hand side is null or undefined and the runs the right hand side.
There's no difference between a function call and a property access.