· tips · 1 min read
The Weirdest JavaScript Quirks You Didn't Know Existed
A deep dive into JavaScript's strangest behaviors - from NaN and == surprises to hoisting, TDZ, floating-point oddities, object key ordering, and event-loop pitfalls - with examples and tips to avoid bugs.

Why JavaScript feels like a funhouse mirror
JavaScript is famously forgiving - and sometimes dangerously permissive. That permissiveness, plus history, floating-point math and implicit coercions, is why you’ll occasionally write code that behaves like it’s playing tricks on you.
Below are some of the weirdest, most baffling JavaScript quirks, with concise examples, explanations and practical advice to avoid getting bitten.
1) NaN is a number… and doesn’t equal itself
Code:
console.log(typeof NaN); // "number"
console.log(NaN === NaN); // false
console.log(Object.is(NaN, NaN)); // true
Why it happens
NaN
stands for “Not-a-Number” but itstypeof
is `