Hey folks, if you have opened this article that means you are curious about these 2 operators, how they operate, and what's the difference between ...
For further actions, you may consider blocking this person and/or reporting abuse
Hey!
I know what you meant, but the
user.fullNamedon't crash. It just returnsundefined.For it to crash you would need
user.fullName.somethingElse.This is because the
userobject exists and it's not a problem to try access keys that don't exist.Also, this could be translation issues, but
??works as||, except, as you said, only withnullandundefined.As a tip: use 3 backticks (
`) plus the language to print code:Great, thanks for the correction Bruno.
Another thing to keep in mind when you're checking for empty string (i.e ""). Nullish Coalescing Operator (??) will return false only if the variable is null. But Optional Chaining Operator (?) will return false if either the value is null or if it's an empty string.
Great, thanks
Just to clarify below code is Not Optional Chaining Operator but Ternary operator.
Nice, i didn't know "??" Seems very helpful
Do give it a shot.
You learn something everyday! :)
Learning never stops :))
I love this article ❤️❤️
Glad to hear it.
Thanks for the article!
It returns true for 0 and false for Unknown and Null
Such an informational feed!
Thanks a lot buddy.
Clear information. Thanks!
I'm happy to help.
Wow, thanks dude for the gain
Most welcome. Follow me for more articles. Happy Friday.
As @noriller has already mentioned, above example is incorrect. Also I would like to mention that ? is not Optional Chaining Operator but ?. is.
I think it would be better if the author could correct the Post to avoid misunderstanding. Thanks.