Null
ELI5 — The Vibe Check
Null means 'intentionally nothing' — a programmer chose to say 'there is no value here'. It is a deliberate absence. If a user has no middle name, you might store it as null. It is different from zero (which is something) and from empty string (which is also something). Null is the void.
Real Talk
Null is a special value representing the intentional absence of any object value. In JavaScript, null is a primitive assigned explicitly to indicate 'no value'. It differs from undefined (which means a variable was declared but never assigned) and from NaN (which is an invalid number). Tony Hoare, who invented null references, called it his 'billion-dollar mistake' due to the null pointer errors it causes.
Show Me The Code
// Explicit null — programmer's choice:
const middleName = null; // person has no middle name
// Checking for null:
if (middleName === null) { /* handle it */ }
if (middleName == null) { /* catches both null AND undefined */ }
// Null vs undefined:
let uninitialised; // undefined — never assigned
const nothing = null; // null — explicitly set to 'no value'
// Optional chaining (safe access):
console.log(user?.address?.city ?? 'No city'); // won't crash if null
When You'll Hear This
"Return null if the user is not found." / "Always guard against null before accessing properties."
Related Terms
NaN (Not a Number)
NaN means 'Not a Number' — it is what JavaScript gives you when math goes wrong in a weird way. Try to parse a word as a number and you get NaN.
Runtime Error
A runtime error is one that only shows up when your program is actually running, not before.
Type
A type tells the computer what kind of thing a value is — is it a number, text, true/false, or a list?
Undefined
Undefined in JavaScript means a variable exists but has never been given a value.