Wtf javascript Memes

Posts tagged with Wtf javascript

JS Is A Very Respectable Language

JS Is A Very Respectable Language
JavaScript really said "consistency is for COWARDS" and honestly? It committed to the bit. ๐Ÿ’€ So you've got an array [1, 2, 3] and you're like "hey what's at index -2?" JavaScript casually returns undefined because negative indices don't exist in JS arrays... EXCEPT when you use .at(-2) which is specifically designed to handle negative indices and suddenly it's like "oh you want the second element from the end? Here's your 2, bestie!" Then you assign foo[-2] = 4 which JavaScript happily accepts because arrays are objects and you just created a STRING property called "-2" on that array object. So now foo[-2] returns 4 from the object property while foo.at(-2) STILL returns 2 from the actual array position. Same syntax, completely different universes. Very respectable. Very normal. Nothing to see here. ๐ŸŽช

Thanks For Inventing JavaScript

Thanks For Inventing JavaScript
JavaScript's type coercion is like that friend who tries to help but makes everything worse. Look at this beautiful chaos: typeof NaN returns " number " because obviously not-a-number is totally a number! Loose equality says true==1 but strict equality says true===1 is false. Make up your mind! Floating point? 0.5+0.1==0.6 is true but 0.1+0.2==0.3 is false. IEEE 754 strikes again! Math.max() with no arguments gives -Infinity while Math.min() gives Infinity . Peak logic. The masterpiece: (1+[]+[]+![]) has length 9 because it converts to "1" + "" + "" + "false" = "1false" And my personal favorite: true+true+true===3 is 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!

Which Of These Javascript Expressions Is False?

Which Of These Javascript Expressions Is False?
The ultimate JavaScript trivia nightmare! Every single option here is a trick question showcasing JavaScript's bizarre type coercion and equality rules: A: typeof null === 'object' is actually TRUE - a notorious JS bug that's been around since the beginning. Null isn't an object, but returns 'object' when typeof'd. B: Math.min() > Math.max() is TRUE too! Without arguments, Math.min() returns Infinity while Math.max() returns -Infinity. C: NaN === NaN is FALSE - the only value in JavaScript that isn't equal to itself! D: 0 == "" is TRUE because JavaScript type coercion converts empty strings to 0. The contestant's face says it all - the answer is C, but knowing JavaScript, you'd question your entire programming career before answering.

Why Brendan Eich Created JavaScript's Quirky Comparisons

Why Brendan Eich Created JavaScript's Quirky Comparisons
JavaScript's type coercion strikes again! In JS, when comparing strings with > , it performs lexicographical comparison - meaning "Dog" > "Cat" evaluates to true because 'D' comes after 'C' in the alphabet. The grumpy kitten represents Brendan Eich (JavaScript's creator) facepalming at his own language quirks. He unleashed these string comparison shenanigans on the world and now even cats are judging him for it. The feline uprising begins with alphabetical order!