JavaScript Array Concatenation Confusion

🤯 This Simple JavaScript Question Confuses Even Experienced Developers I asked this in a frontend interview… and surprisingly, many developers got it wrong 👀 ❓ Question What will be the output? console.log([] + []); Take a second and think… ✅ Actual Output "" Yes — an empty string, not an array. 🔍 Why This Happens In JavaScript, the + operator behaves differently based on operands. 👉 When used with arrays or objects, JavaScript tries to convert them into primitives (strings). So internally: [] → "" "" + "" → "" That’s why the result is an empty string. 🔥 Let’s Go Deeper console.log([] + {}); 👉 Output: "[object Object]" Why? • [] becomes "" • {} becomes "[object Object]" • Final result → string concatenation 🎯 What Interviewers Are Testing This is not a trick question. It checks: ✔ Type coercion understanding ✔ How JavaScript converts values internally ✔ Behavior of + operator with non-primitives 💡 Reality Check JavaScript looks simple… until you hit edge cases like this. And that’s exactly why: 👉 Interviews focus on fundamentals, not just frameworks If you understand how JavaScript thinks, you’ll rarely get stuck on such questions. 💬 What’s the most confusing JavaScript output you’ve ever seen? #JavaScript #FrontendDevelopment #CodingInterview #WebDevelopment #Programming #Developers #JSConcepts #InterviewPreparation 👉 Follow Rahul R Jain for more real interview insights, React fundamentals, and practical frontend engineering content.

🔥 Classic JavaScript moment 😄 🧠 This is why type coercion trips even experienced devs 👉 JS doesn’t “add” here — it converts + concatenates 💡 Biggest takeaway: Understand JS internals > memorizing frameworks 💯 Great interview question! #JavaScript #FrontendDevelopment #WebDevelopment #Programming #JSConcepts #CodingInterview

[] == ![] still breaks my brain every time 😅

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories