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.fullName
don't crash. It just returnsundefined
.For it to crash you would need
user.fullName.somethingElse
.This is because the
user
object 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 withnull
andundefined
.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.
You learn something everyday! :)
Learning never stops :))
Thanks for the article!
Nice, i didn't know "??" Seems very helpful
Do give it a shot.
I love this article ❤️❤️
Glad to hear it.
Such an informational feed!
Thanks a lot buddy.
It returns true for 0 and false for Unknown and Null
Wow, thanks dude for the gain
Most welcome. Follow me for more articles. Happy Friday.
Clear information. Thanks!
I'm happy to help.
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.