logo

if ([]) console.log("truthy"); // Runs! if ({}) console.log("truthy"); // Runs! Empty array and empty object? Truthy. But if ([] == false) ? That’s true (see point #2). Consistency? Not today. JavaScript defines weird type coercion rules for + .

Both get converted to strings and concatenated. Not an error. Not useful. Just... weird. JavaScript’s weird parts aren’t bugs—they’re historical artifacts. Brendan Eich built this language in 10 days in 1995. It had to be flexible, forgiving, and fast.

console.log(typeof NaN); // "number" According to the IEEE 754 floating-point spec (which JS uses), NaN is a numeric data type that represents an invalid number. It’s a number that isn’t a number. The weirdness doesn't stop there: javascript weird parts

Use a small epsilon or multiply by powers of 10 for money calculations (or use BigInt for integers). 5. Automatic Semicolon Insertion (ASI) JavaScript tries to be helpful. Sometimes too helpful.

These quirks are frustrating until you understand why they exist. Once you do, you stop fighting the language and start leveraging it. if ([]) console

console.log(NaN === NaN); // false Yes, NaN is not equal to itself. You must use Number.isNaN() instead. This is the gateway drug of JS weirdness.

function show() { console.log(this); } show(); // window (or global in Node) new show(); // {} (the new instance) Truthy

console.log(1 + "2"); // "12" (string) console.log(1 + 2 + "3"); // "33" (evaluates left to right: 3 + "3") console.log([] + []); // "" (empty string) console.log([] + {}); // "[object Object]" console.log({} + []); // 0 (Wait, run this in a console... yes, 0) The last one is a parsing edge case where {} is interpreted as an empty code block, not an object. This one angers accountants and mathematicians equally.