JavaScript Array to String Conversion in Frontend Interviews

JavaScript question in a frontend interview… and many developers dont know answer👀 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

To view or add a comment, sign in

Explore content categories