null vs undefined in JavaScript
undefined means no value assigned — uninitialized variables, missing arguments, absent properties, void function returns. null means deliberately empty — assigned by programmers to signal intentional absence. Both are falsy, both == each other, and they diverge everywhere else.
Convention: let the language produce undefined (don't assign it yourself), assign null for intentional emptiness, and default both away with ?? or default parameters. typeof null === "object" is a 1995 bug now permanent — check null with === null, never typeof.
undefined: never given
Declared-but-unset variables, missing args, absent keys, void returns — the language's own I-don't-have-one.
null: deliberately empty
Assigned by people meaning nothing-here-on-purpose — the intentional counterpart to undefined's accidental.
== equates, === separates
null == undefined is true (the one sanctioned loose equality); === keeps them distinct — prefer === plus explicit handling.
typeof null lies
typeof null === "object" is a fossilized bug — use x === null for null checks, typeof only for undefined.
let a;let b = null;console.log(a, b);console.log(a == b, a === b);Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.