Student-friendly HTML, CSS, and JavaScript reference with examples
undefined === null // falseJavaScript has three different ways to represent “nothing,” and they’re not the same.
let a; // undefined — never given a value
let b = null; // null — explicitly set to nothing, on purpose
let c = ""; // "" — an empty string, still text, just empty
None of them are equal to each other:
undefined === null // false — both mean "nothing", but different types
null === "" // false
undefined === "" // false
undefined happens by accident — a variable exists but nobody’s given it a value yet.
null happens on purpose — you’re saying “this is intentionally empty.”
"" isn’t nothing — it’s a real string, just zero characters long. It still behaves like
text:
"".length // 0
"" + "hello" // "hello"