A variable is undeclared if it has not been declared with an appropriate keyword (i.e.
const). Accessing an undeclared variable will throw a
console.log(x); // ReferenceError: x is not defined
A variable is
undefined if it hasn't been assigned a value.
let x; console.log(x); // undefined
A variable is assigned a value of
null like any other value.
let x = null; console.log(x); // null
Checking for empty states
Undeclared variables will throw an error, which makes them easy to spot and are not very common anyways.
null can be easily spotted with a conditional as they are both falsy values. Due to that,
undefined are loosely equal (
==), but not strictly equal (
Object.is()and the triple equals operator (