JavaScript: undefined

By Xah Lee. Date: . Last updated: .

undefined is the value of the property key "undefined" of the Global Object.

console.log( window["undefined" ] === undefined ); // true

undefined is a literal value. For example, you can write let x = undefined;

Type of undefined is "undefined", and it is the only value of the type.

console.log( typeof undefined === "undefined" ); // true

undefined is the value when:

let x;
console.log(
 x === undefined
); // true
// accessing non-existent property returns undefined
const o = {"p":1};
console.log(
 o.b === undefined
); // true
// accessing out-of-bound array element returns undefined
const arr = ["a", "b"];
console.log(
 arr[9] === undefined
); // true
// When function argument is not given, value is undefined
function f(x) { return x; };
console.log(
 f() === undefined
); // true
// undefined is the return value of a function call when the function doesn't have return statement
function f() {};
console.log(
 f() === undefined
); // true
// undefined is the return value of a function with empty return statement
function f() {return;};
console.log(
 f() === undefined
); // true

[see null]

∑ JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Static Objects

Primitive Wrapper

Special Objects