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 →
- What is a closure in JavaScript?
A closure is a function that remembers the variables from the place where it was created, even after that outer function has finished running.
BeginnerIn-depth2 min read - What is the difference between == and === in JavaScript?
=== (strict equality) is true only if both values have the same type and the same value. == (loose equality) first converts the values to a common type and then compares, which gives surprising results like 0 == "" being true. Use === by default.
BeginnerIn-depth3 min read - What is the difference between promises and async/await, and how do you handle errors with each?
async/await is cleaner syntax built on top of promises. An async function always returns a promise, and await pauses that function until a promise settles. With promises you handle errors using .catch(); with async/await you use try/catch around the await.
BeginnerIn-depth3 min read - What is the difference between var, let and const? Explain hoisting and the temporal dead zone.
var is function-scoped and is hoisted with the value undefined. let and const are block-scoped and are hoisted too, but cannot be used before their declaration line; that gap is the temporal dead zone. const also cannot be reassigned, though an object it holds can still be changed.
BeginnerIn-depth3 min read