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

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 its typeof is `
Back to Blog

Related Posts

View All Posts »
Understanding the Event Loop: Myths vs. Reality

Understanding the Event Loop: Myths vs. Reality

Cut through the noise: learn what the JavaScript event loop actually does, why common claims (like “setTimeout(0) runs before promises”) are wrong, how browsers and Node differ, and how to reason reliably about async code.

Microtasks vs Macrotasks: The Great JavaScript Showdown

Microtasks vs Macrotasks: The Great JavaScript Showdown

A deep dive into microtasks and macrotasks in JavaScript: what they are, how the event loop treats them, how they affect rendering and UX, illustrative diagrams and real-world examples, plus practical guidance to avoid performance pitfalls.

Parsing JSON: A Deep Dive into Edge Cases and Surprising Pitfalls

Parsing JSON: A Deep Dive into Edge Cases and Surprising Pitfalls

A practical, in-depth exploration of advanced JSON parsing and stringifying behaviors in JavaScript - covering NaN/Infinity, -0, BigInt, Dates, functions/undefined, circular references, revivers/replacers, prototype-pollution risks, streaming large JSON, and safe patterns you can apply today.