Is there a shorter way to checking if a value in JavaScript is null or undefined than this using new ES10 features like Nullish Coalescing?
(value !== null && value !== undefined)
There were other questions like
- Detecting an undefined object property in JavaScript
- How to determine if variable is 'undefined' or 'null'
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
But they all use either loose equality (==), use jQuery or return false even if the value is "", [] or 0.
value == nulleslint? TheeqeqeqESLint rule has thesmartoption for allowing exactly this type of usage: eslint.org/docs/rules/eqeqeq((value ?? null) !== null)I guess?(value ?? null) !== nullmight work but is totally weird. I would not recommend to write code like that, it's just a source of confusion.value == nullis short, precise, well-known and idiomatic. Nothing about that changed with ES2020.