You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using optional chaining, we can eliminate these temporary variables:
anObject?.N$_f_foo()?.N$_f_bar()?.N$_f_baz()
Unfortunately, optional chaining returns undefined rather than null when it short-circuits. During implicit conversions, undefined becomes NaN rather than 0. Hence, the following:
[anObject foo] + 5
will now be NaN if anObject is null.
We can use nullish coalescing to ensure that messaging results are null:
Currently, we need to use temporary variables to store the result of each message. For example:
[[[anObject foo] bar] baz]
becomes:
Using optional chaining, we can eliminate these temporary variables:
Unfortunately, optional chaining returns
undefined
rather thannull
when it short-circuits. During implicit conversions,undefined
becomesNaN
rather than0
. Hence, the following:[anObject foo] + 5
will now be
NaN
ifanObject
isnull
.We can use nullish coalescing to ensure that messaging results are
null
:(anObject?.N$_f_foo()?.N$_f_bar()?.N$_f_baz())??null
Note: this would subtly change falsy messaging - messaging
undefined
would returnnull
instead ofundefined
.The text was updated successfully, but these errors were encountered: