Interview Q&A / JavaScript
JavaScript interview questions
Closures, the event loop, this, promises and the core language questions every frontend round asks.
Prefer rapid revision? Practise JavaScript short interview answers →
- How do Number(), parseInt() and the unary plus differ when converting a string to a number?
Number() and unary + are strict: any junk gives NaN. parseInt reads digits from the left and stops at the first non-digit, so "42px" gives 42. Always pass a radix to parseInt.
BeginnerQuick answer1 min read - What are truthy and falsy values in JavaScript?
When a value is used in a condition, JavaScript converts it to a boolean. Only eight values become false: false, 0, -0, 0n, empty string, null, undefined and NaN. Everything else, including [] and {}, is truthy.
BeginnerQuick answer1 min read - What is the difference between implicit and explicit type coercion?
Explicit coercion is when you convert on purpose, like Number("5") or String(5). Implicit coercion is when JavaScript converts for you during an operation, like "5" * 2 or if (value).
BeginnerQuick answer1 min read - Why does "5" + 3 give "53" but "5" - 3 give 2?
The + operator does string concatenation if either side is a string, so 3 becomes "3". The -, * and / operators only work on numbers, so they convert "5" to 5 first.
BeginnerQuick answer1 min read - What do [] + [] and [] + {} evaluate to in JavaScript?
[] + [] is the empty string and [] + {} is "[object Object]". The + operator turns both sides into strings when neither is a number, and an empty array stringifies to an empty string.
IntermediateQuick answer1 min read - Why does [] == ![] return true in JavaScript?
![] is false because an array is truthy. Then [] == false converts both sides to numbers: [] becomes "" then 0, and false becomes 0, so 0 == 0 is true.
AdvancedQuick answer1 min read