Who Would Have Thought

Who Would Have Thought
javascript-memes, arrays-memes, in-operator-memes, javascript-quirks-memes, type-coercion-memes | ProgrammerHumor.io

JavaScript's in operator strikes again with its beautiful chaos. Someone proudly declares JavaScript as their favorite language, then immediately demonstrates why checking if 1 in [1,3,5,7] returns true while 7 in [1,3,5,7] returns false.

Here's the kicker: the in operator checks for array indices, not values. So 1 in [1,3,5,7] checks if index 1 exists (it does—it's the value 3), and 7 in [1,3,5,7] checks if index 7 exists (nope, array only has 4 elements). Classic JavaScript move: making perfect syntactic sense while being semantically bonkers.

The person gets immediately thrown out the window, as one should when defending JavaScript's "features." Use .includes() like a civilized developer, people.

More Like This