If you need to check whether a value is set i.e. not undefined
or null
, what would be the most convenient way to do it that does not sacrifice readability?
Here are some of the options I have been using:
Clear and exact but long:
if (value !== null && value !== undefined) {...}
Short, exact but not clear
if (value != null) {...}
Short, not exact and not clear
if (!value) {...} // true with 0, NaN and empty string