JavaScript Weirdness That Blows Minds Did you know? NaN === NaN returns false Yes, you read that right. In JavaScript, NaN (Not a Number) is the only value that is not equal to itself. Why? Because NaN represents an invalid or undefined numeric result. And according to how JavaScript handles numbers internally, different invalid operations can produce different “NaN-like” values, so they are not considered equal. console.log(NaN === NaN); // false So how do you check it correctly? Number.isNaN(NaN); // true Bonus: typeof NaN // "number" Yes… it's a number too JavaScript isn’t weird… it’s just misunderstood. #JavaScript #WebDevelopment #Programming #Coding #Frontend #LearnToCode #DevTips
This is not a JS weirdness, numbers in JS follow the IEEE-754 64-bit binary number format, which in addition to regular floating point numbers also defines special number values such as +Infinity and -Infinity and several types of NaN, which is the result of certain illegal operations. The same behavior can be observed in C/C++, Java, Python, Rust, etc. Another JS specific fun fact: [] != []
Wholly agree! When you really delve into them, the vast majority (maybe all) of the things about JS that SEEM "weird" actually have extremely logical reasons for existing and functioning the way they do. JS is very misunderstood...sadly. One of my favorite languages, though! I think I've been more productive and produced more value with JS, than any other language, in my ~30 year career.
JavaScript is weird stop making excuses for it 😂 but it gets shit done and I guess that’s the reason for its initial adoption
Similar thing in python Null ==Null Return false
In fact JS is weird, but this makes a few sense
This one never gets old 😄 JavaScript really said: “I know what I’m doing… trust me.” The NaN behavior makes more sense once you think of it as “unknown result” rather than a concrete value—but yeah, still feels cursed the first time you see it. Another fun one: [] + [] // "" But… [] + {} // "[object Object]" Same operator, wildly different vibes. JavaScript isn’t weird… it just rewards curiosity (and punishes assumptions).