Undefined
suggest changeA let or var declaration without an initializer has the value undefined after the declaration executes:
let a;
console.log(a); // logs: undefined
Reading an undeclared identifier normally throws a ReferenceError. The typeof operator is a special case: it returns "undefined" for an undeclared identifier, which makes it useful for guarded feature checks. It also returns "undefined" for a declared binding whose value is undefined:
let a;
console.log(typeof a === "undefined"); // logs: true
console.log(typeof variableDoesNotExist === "undefined"); // logs: true
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents