Documentation

Student-friendly HTML, CSS, and JavaScript reference with examples

Sections

Undefined, Null, and Empty String

undefined === null // false

JavaScript 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 vs null

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.”

Empty String Is Still Data

"" isn’t nothing — it’s a real string, just zero characters long. It still behaves like
text:

"".length            // 0
"" + "hello"         // "hello"