JavaScript quirks and surprises: Arrays, Maps, and more

🚨 JavaScript looks simple… until you start learning its quirks. Today I had a learning session on JS, and honestly, it reminded me why this language is both powerful and weird at the same time. Some things look obvious… until you realize JavaScript behaves differently than you expected. Here are a few insights that made me pause today 👇 🔹 Arrays can act like a deque Push, pop, shift, unshift -- both ends are usable. 🔹 Arrays compare by reference, not value Two identical arrays are still different objects. 🔹 sort() is tricky By default it sorts lexicographically, not numerically. 🔹 [Symbol.iterator] defines iterables If an object implements it, you can loop through it. 🔹 Array-likes exist Objects like String, arguments, and NodeList have indexes and length, but they are not real arrays. 🔹 Map vs Set Map → key/value with flexible keys Set → collection of unique values 🔹 WeakMap & WeakSet They store weak references, which helps JavaScript’s garbage collector automatically clean up unused objects 🤠 And of course… JavaScript Date -- the old sheriff in town. Every time I study JS deeper, I realize how many hidden behaviors it has. What’s the most confusing JavaScript concept you’ve learned recently? #JavaScript #WebDevelopment #CodingJourney #FrontendDevelopment #LearnInPublic

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories