I Asked 30 Developers This JS Question — Only 2 Got It Right

Type coercion fundamentals.

Image for -I Asked 30 Developers This JS Question — Only 2 Got It Right

A few weeks ago, I asked a simple JavaScript question to a bunch of developers — some juniors, some mid-level, and even a few seniors. The kind of question you’d expect most people to breeze through. But guess what? Out of 30 developers, only 2 got it right.

That shocked me.
Not because the others were bad at their jobs. But because JavaScript can be sneaky, and even the smartest devs sometimes overlook the basics.

The Question That Started It All

Here’s what I asked:

console.log([] + []);
console.log([] + {});
console.log({} + []);

Most devs paused. Some said, “undefined.” A few guessed “error.” Only two gave the correct answers and explained why.

Before I reveal the answers, take a moment. What would you expect?

Race Gif

The Answers (And Why They Matter)

console.log([] + []); // ""
console.log([] + {}); // "[object Object]"
console.log({} + []); // 0 (but this one's tricky!)

If you’re scratching your head — good. You’re not alone.

When I saw this question I scratched my head😅 and thought what type of question is this?

What’s happening here is type coercion. JavaScript tries to convert non-strings or non-numbers into something it can work with, and in doing so, it makes decisions that might not be obvious as JavaScript behaves in its own way.

  • The first line adds two empty arrays. Since arrays are objects, JavaScript converts them into empty strings, resulting in "".
  • The second one? The array becomes an empty string again, and the object becomes "[object Object]". So together: "[object Object]".
  • The last one depends on how the code is parsed. If you write {} at the beginning of a line, JS treats it as a block, not an object. So this becomes:
+[] // which is 0

Mind-bending, right?

Why You Should Care

This isn’t just about getting quirky interview questions right. It’s about understanding the language you work with daily. These subtle behaviours are what often lead to bugs, unexpected results, or that dreaded “why isn’t this working?” moment at 2AM.

Knowing these things doesn’t just make you a better problem solver — it makes you more confident in interviews, pair programming, and even when reviewing someone else’s code.

So, What’s the Takeaway?

You don’t have to memorize all the weird JS edge cases. But you do need to develop the habit of asking why something works the way it does.

I know, this is a very rare type of question which mostly no one expects you to know, but just thought of sharing it as I found it very interesting.

JavaScript is powerful — but only if you respect how it thinks.

And hey, if this stumped you too, you’re in good company. 😉
The point isn’t to be perfect. The point is to keep getting curious.

At Dev Simplified, We Value Your Feedback 📊

👉 Want to write with us? Join us on our whatsapp channel

👉 Have any suggestions? Let us know in the comments!

👉 Subscribe for free and join our growing community!