Member-only story
10 Mind-Bending JavaScript Interview Questions Explained
JavaScript interviews can be tricky. Sometimes, you get questions that seem simple but have surprising answers. These questions test how well you really know the language.
In this article, I’ll break down 10 mind-bending JavaScript interview questions in the simplest way possible. No confusing terms — just clear explanations.
Let’s get started!
1. What Does 1 + "1" - 1
Equal?
Question:
console.log(1 + "1" - 1);
What You Might Think:
1 + 1 = 2
, then2 - 1 = 1
. So, the answer should be1
.
What Actually Happens:
JavaScript sees 1 + "1"
and thinks: "One of them is a string, so I’ll convert both to strings and combine them."
1 + "1"
becomes"11"
(string).
Now, "11" - 1
forces JavaScript to treat "11"
as a number.
11 - 1 = 10
.
Final Answer: 10
Why This Matters:
- JavaScript changes types automatically (called type coercion).