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 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 - How do default values and renaming work in object and array destructuring?
In objects, {name: n = 'x'} reads property name into variable n with a default used only when the value is undefined. In arrays, position matters: [a, , c = 9]. Defaults ignore null.
BeginnerQuick answer1 min read - What are template literals and why are they better than string concatenation?
Template literals use backticks. They allow ${expression} interpolation and multi-line strings without escape characters, which makes strings with variables far easier to read than chains of + signs.
BeginnerQuick answer1 min read - What is the difference between the spread and rest operators?
Both are written as three dots. Rest collects many values into one array or object, in function parameters and destructuring. Spread expands one array or object into many items, in calls and literals.
BeginnerQuick answer1 min read