JavaScript's type coercion is like that friend who tries to help but makes everything worse. Look at this beautiful chaos:
typeof NaNreturns "number" because obviously not-a-number is totally a number!- Loose equality says
true==1but strict equality saystrue===1is false. Make up your mind! - Floating point?
0.5+0.1==0.6is true but0.1+0.2==0.3is false. IEEE 754 strikes again! Math.max()with no arguments gives-InfinitywhileMath.min()givesInfinity. Peak logic.- The masterpiece:
(1+[]+[]+![])has length 9 because it converts to "1" + "" + "" + "false" = "1false" - And my personal favorite:
true+true+true===3is actually true because JavaScript converts booleans to numbers for addition!
No wonder the creator is smirking. He unleashed this beautiful monster on us and now we're all stuck with it. And we can't even escape because the entire web runs on it!
AI
AWS
Agile
Algorithms
Android
Apple
Bash
C++
Csharp