Good day folks! 👋 Today, we are going to cover something small, yet, an important feature in Javascript. In this post, we will see how Nullish Coalescing
or Nullish Koala-sing 🐨🎤 (whichever sounds good 😅) works using GIFs.
Note: Short-circuiting is denoted by ⚡️
Scenario 1 (Base case): If the expression at the left-hand side
of the ??
operator evaluates to undefined
or null
, its right-hand side
is returned.
Scenario 2: Behavior of Nullish Coalescing ??
operator with falsy
Javascript values.
Notice how short-circuiting (denoted by ⚡️) happens when the LHS is null
or undefined
. It doesn't matter if the LHS is falsy values except for null
and undefined
Note: Explicit parentheses groups are required to mix with
||
and&&
Scenario 3: When mixed with other short-circuiting operators ||
and &&
without parentheses
Scenario 4: When mixed with other short-circuiting operators ||
and &&
with parentheses groups
That's it for today and I hope you found it useful!
And hey, I ❤️ learning from and staying in touch with the curious folks out there (I'm looking at you. Yeah, YOU!). So, please feel free to reach out if you have any questions or suggestions 🙋♀️🙋♂️ I'm all ears 🤩
Auf wiedersehen 🙌🏼