Recent JavaScript updates have introduced ??
and ?.
to perform operations like locating the first non-nullish expression or referencing an object if it is not null.
[Additional Note: "nullish" indicates values that are either "null
" or "undefined
", as seen in the nullish coalescing operator].
Is there a more idiomatic approach to simply check for non-nullishness? For instance, determining whether to execute an onChange()
handler only if the value is non-nullish. Like this:
someVal && onChange(someVal)
This method has its flaws since it would not work with falsy but still non-nullish values (such as 0
and ''
).