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.
If you’ve spent more than 48 hours with JavaScript, you’ve probably uttered the phrase: “Wait… why did it do that?” javascript weird parts
const obj = { show }; obj.show(); // obj console
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. If you’ve spent more than 48 hours with
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.