Member-only story
The Quirky World of JavaScript: Exploring Its Funniest and Strangest Quirks 🤯🚀
JavaScript is like that one eccentric friend who always manages to surprise you. Just when you think you’ve got it all figured out, BOOM! Another unexpected behavior pops up, leaving you scratching your head. 🤔 Whether you’re a seasoned developer or just starting out, JavaScript’s quirks make coding an exciting (and sometimes frustrating) journey.
So, let’s dive into some of the weirdest, most fascinating quirks of JavaScript and why they happen! 🕵️♂️💻
🎭 The Empty Array + Empty Array Mystery
Ever tried this in your browser’s console?
console.log([] + []);You’d expect an empty array, right? But nope! JavaScript surprises you with an empty string ("").
🤯 Why Does This Happen?
The + operator in JavaScript is both an arithmetic addition operator and a string concatenation operator. When used with arrays, JavaScript first converts them to strings using .toString().
Since [].toString() returns an empty string (""), adding two empty arrays together results in:
"" + "" // → ""💡 Takeaway: Always be mindful of implicit type conversions in JavaScript!
🧐 null is an Object? Wait, What?!
console.log(typeof null); // "object"







