void 0 always evaluates to undefined and cannot be shadowed. It is used in old code and minified output to safely get undefined when the global property might have been reassignable. In modern JS (ES5+), x === undefined is sufficient.
How to Check for undefined in JavaScript
What is void 0 in JavaScript and why is it used?
The answer
More FAQs in How to Check for undefined in JavaScript
Use strict equality: x === undefined. This checks both type and value. It is the canonical, safe way to check if a declared variable has the value undefined.
Because !x also catches null, 0, '', false, and NaN. If you only want to check for undefined, use === undefined. Use !x only when you want to catch all falsy values.
Use typeof. typeof an undeclared variable returns 'undefined' without throwing. For example: if (typeof someGlobal !== 'undefined') is safe for feature detection.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.