I asked this JavaScript question in a frontend interview… and many developers got it wrong. 👀 Question: What will be the output? console.log([] + []); Take a moment and think. Most developers expect an array as output. But the actual output is: "" Yes — an empty string. Why does this happen? In JavaScript, when we use the + operator with arrays, they are converted to strings first. [] → "" So internally JavaScript does this: "" + "" = "" That’s why the result is an empty string. Now it gets more interesting: console.log([] + {}); Output: "[object Object]" Because the object converts to a string representation. Why interviewers ask this They want to check your understanding of: Type coercion JavaScript internal conversions How the + operator works JavaScript can look simple… but its behavior can surprise even experienced developers. Frontend interviews don’t just test frameworks — they test JavaScript fundamentals. #JavaScript #FrontendDevelopment #CodingInterview #WebDevelopment #Developers #Programming
I don't know why people ask these types of cheap questions. There are lots of imp things to discuss in the interview.
Just ask them back: in which case these knowledge are important?
My first question would be if you just want the above answer why do you ask them? I think the real intent of asking this question should be beyond knowing that it's "coercion" , it should be checking if developer ever checked algorithms of these conversations on ECMA spec specifically what happens when an operation is performed on two different data types. How the internally it uses hints and make use of internal methods like valueof, toString and toprimitive. Warna question puchna bekar h.
Have you asked them back, ‘Have you ever coded like this in a real project?
What's the use of such useless questions
I have given 80+ frontend interviews till now and no one asked this. Looks like ChatGPT generated 😂
I think the issue with this question is knowing the answer doesn’t actually help you understand JavaScript in actual action. A better question is, “Are promises Push or pull?”
No developer in their right mind would try to add an object to an array, it's the kind of knowledge you get when you don't know what you are upto and just code randomly. No real-life use case scenario.
In the world of Typescript it’s pointless to ask this kind of questions.
Keep sharing