Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The undefined global property represents the primitive value undefined. It is one of JavaScript's primitive types.
The primitive value undefined.
| Writable | no |
| Enumerable | no |
| Configurable | no |
undefined is a property of the global object. That is, it is a variable in global scope.
In all non-legacy browsers, undefined is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.
A variable that has not been assigned a value is of type undefined. A function returns undefined if a value was not returned. Accessing a property that does not exist also returns undefined. The void operator always returns undefined.
Note: While you can use undefined as an identifier (variable name) in any scope other than the global scope (because undefined is not a reserved word), doing so is a very bad idea that will make your code difficult to maintain and debug.
You can use undefined and the strict equality and inequality operators to determine whether a variable has a value. In the following code, the variable x is not initialized, and the if statement evaluates to true.
Note: The strict equality operator (as opposed to the loose equality operator) must be used here, because x == undefined also checks whether x is null, while strict equality doesn't. This is because null is not equivalent to undefined.
See Equality comparison and sameness for details.
typeof can also determine whether a variable is undefined:
One reason to use typeof is that it does not throw an error if the variable does not exist in the current scope.
It also works with variables declared with var after the check, because the declaration is hoisted to the top of the scope with value undefined.
This technique is usually only useful for testing global variables. You can know if a variable exists at any other scope (blocks, functions, modules, etc.) just by looking at the source code. The global scope is bound to the global object, so checking the existence of a variable in the global context can be done by checking the existence of a property on the global object, such as by using the in operator:
However, none of the techniques above work if the variable is declared with let, const, or other lexical declarations. Using typeof before the line of declaration still produces a ReferenceError, due to the temporal dead zone (TDZ).
Furthermore, let and const declarations do not create properties on the global object, so they cannot be checked with the in operator either.
If you want to share global variables across different scripts, it is more advisable to use var or explicitly attach them to the global object:
The void operator can also be used to produce the undefined value. This is very commonly seen in minified code because void 0 is 3 bytes shorter and cannot be overridden. You should usually avoid this pattern in your own code.
| ECMAScript® 2027 Language Specification # sec-undefined |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jan 10, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.