#1: typeof null
Topic: misc · Difficulty: ★
console.log(typeof null);Output
object
Why
typeof null returns "object" — one of the oldest bugs in JavaScript. In the very first engine, values carried a type tag, and the tag for objects was 0. null was represented as the NULL pointer (all zero bits), so its tag read as 0 too, and typeof reported "object". Fixing it would break too many existing sites, so the bug was standardized forever. To actually test for null, compare directly: value === null.
More misc puzzles