Check for undefined in JavaScript

javascript

Updated August 29, 2026

Use strict equality when checking a value that should be exactly undefined:

const value = undefined;

if (value === undefined) {
  console.log('value was not provided');
}

For a variable that may not have been declared at all, typeof avoids a ReferenceError:

if (typeof optionalFeature === 'undefined') {
  // the binding does not exist, or its value is undefined
}

undefined is different from null, which is an intentional “no value” marker in many APIs. A missing object property also evaluates to undefined, but "key" in object distinguishes a missing property from a property explicitly assigned that value.

Avoid value == null unless you deliberately want it to match both null and undefined. In function parameters, default values apply to undefined but not to null: function f(value = 1) {}.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author