Skip to content

Null

Easy — everyone uses thisGeneral Dev

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

Made with passive-aggressive love by manoga.digital. Powered by Claude.