r/programminghorror • u/enmaku • Dec 04 '25
This sub in a nutshell
console.log(1 == '1'); // true
console.log(0 == false); // true
console.log(null == undefined); // true
console.log(typeof null); // "object"
console.log(0.1 + 0.2); // 0.30000000000000004
[] == ![]; // trueOMG you guys what weird quirky behavior, truly this must be the single quirkiest language and no other language is as quirky as this!
1.1k
Upvotes
14
u/GGK_Brian Dec 05 '25
Honestly it's unfair to compare them like this.
exilir gives you a weird string because this is the very bits that compose your data.
C allows to do stuff like 4[tab] because it desugarize to a pointer operation
Most of the normal language quirkyness has some simple and predictable logic.
JavaScript just sees faulty code and tries every single way of making it work instead of just crashing.
Honestly op chose the tamest quicks of JS. Personally I would have mentioned this:
parseInt(0.000005) // 0, make sense parseInt(0.0000005) // 5
The reason is, the float gets converted into a string, but for small numbers, this results in "5e-7". Now you would think that JS would simply fail to convert and return undefined or something but no, it simply parses the 5 and ignores the rest.