Image for post
Image for post

The Top 10 Things Wrong with JavaScript


0.1 + 0.2 → 0.30000000000000004
0.1 + 0.2 === 0.3 → false // ???
x = 1.0000000000000001
x === 1 → true // ???
typeof NaN → "number" // NaN is a number??? But...
NaN != NaN → true
NaN !== NaN → true
[] + [] → "" // Empty string? These are arrays!
[] + {} → [object object]
{} + [] → 0 // Why isn't the operation commutative???
{} + {} → NaN // ???
16 == [16] → true // Array converted into string, then into number
16 == [1,6] → false // But what is array converted into?
"1,6" == [1,6] → true
var arr = [];
arr.length → 0
arr[3] → "undefined" // No array bounds exception???
arr[3] = "hi";
arr.length → 4 // 4??? Only one element has been added!
arr["3"] → "hi" // Apparently "3" is coerced into a number
delete(arr[3]);arr.length → 4 // 4??? There are no elements in the array!
arr[3] → "undefined" // 7 lines above, length was "0"!
var i = 1;
i = i + ""; // Oops!
i + 1 → "11"
i - 1 → 0
var j = "1";
++j → 2 // Okay, but...

var k = "1";
k += 1 → "11" // What???

[1,5,20,10].sort() → [1, 10, 20, 5] // Why is it sorting strings???
xs = ["10", "10", "10"];
xs.map(parseInt) → [10, NaN, 2] // ???
y = {};
y[[]] = 1;
Object.keys(y) → [""]
Image for post
Image for post

JavaScript Non Grata

Just say no to this abomination

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store