Tricky JavaScript Interview Questions
Short answer
These are the questions designed to trip you up. Know the reasoning and they become easy.
Why is 0.1 + 0.2 not equal to 0.3?
All JS numbers are 64-bit floats; 0.1 and 0.2 can't be represented exactly in binary, so the sum is 0.30000000000000004. Compare floats within Number.EPSILON or work in integers.
Why is NaN not equal to itself?
NaN === NaN is false by design — it's the only value not equal to itself. Use Number.isNaN(x) to test for it.
This is 1 of 80+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299What does typeof null return, and why?
'object' — a historic bug kept for backward compatibility. The only reliable null check is x === null.
What prints: closures in a loop?
var shares one binding, so deferred callbacks read the final value (3 3 3); let creates a fresh binding per iteration (0 1 2).
What is the output of promise vs setTimeout?
Sync first, then microtasks (promises), then macrotasks (setTimeout) — so a .then always beats a 0ms setTimeout.
Frequently asked questions
- How do I prepare for tricky JS questions?
- Learn the underlying models — floating point, coercion, the event loop, closures — instead of memorising individual answers.
- Are these actually asked?
- Yes, frequently — they're quick to pose and reveal whether you truly understand JavaScript.
This is 1 of 80+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299