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
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 (
Checks if the a value is an empty object/collection, has no enumerable properties or is any type that is not considered a collection.
Object.is() and the triple equals operator (
Checks if the specified value is