JavaScript interview questions and answers
A JavaScript technical interview almost always covers variable scope (var, let and const), closures, the value of this and async code: promises, async/await and the event loop. These topics are easier to understand by reading code, which is why you’ll often be asked to predict what a snippet prints.
These are questions Syntax, the recruiter in SyntaxQuest’s mock interview, may ask you for frontend, backend and full-stack roles, each with a short, verified answer, plus three code snippets to practice with.
JavaScript technical questions
Short answers, the way you would say them out loud. If you can explain them in your own words and give an example, you’re on the right track.
-
What’s the difference between var, let and const?
var is function-scoped and can be used before its declaration (it’s undefined). let and const are block-scoped. const prevents reassigning the variable, but it doesn’t freeze the object: you can still change its properties or an array’s items.
-
What is a closure?
A function that remembers the variables of the scope where it was created, even after that scope has finished. It’s the basis of counters, modules with private data and callbacks that keep state.
-
What’s the difference between == and ===?
=== compares value and type with no conversion. == converts types before comparing and gives surprising results: '1' == 1 is true. Use === by default.
-
What is the event loop?
The mechanism that enables asynchronous code on a single thread. When the call stack is empty, it first runs all pending microtasks (such as promise callbacks) and then the next task in the queue (such as a setTimeout or an event).
-
What is a Promise and what states does it have?
An object that represents a value that will arrive later. It starts as pending and settles as fulfilled (with a value) or rejected (with an error); once settled, it doesn’t change. async/await is a more readable way to work with promises.
-
What does Array.prototype.map do, and how is it different from forEach?
map applies a function to each element and returns a new array with the results, without changing the original. forEach just iterates and returns undefined. Use map when you need the result and forEach for side effects, like logging.
-
What is hoisting?
Before running a scope, JavaScript registers its declarations. Function declarations can be called before their line, and var exists from the start with the value undefined. let, const and class are registered too, but using them before their declaration throws a ReferenceError: that’s the temporal dead zone.
-
What is this and how does it change by context?
It depends on how the function is called: in a method, it’s the object before the dot; in a standalone function, it’s undefined in strict mode (the global object otherwise); with new, the new object; and with call, apply or bind, whatever you pass. Arrow functions have no this of their own: they use the outer scope’s.
-
What’s the difference between null and undefined?
undefined means something has no value: an unassigned variable, a missing property or a function without return. null is an intentional absence of value set by the programmer. null == undefined is true, but null === undefined is false.
-
What does the spread operator (...) do?
It expands an array or object into its elements: use it to copy ([...arr]), merge ({...a, ...b}) or pass arguments (Math.max(...nums)). Copies are shallow: nested objects are still shared.
Code questions: what does it print?
Many interviews show you a short snippet and ask you to predict the result and explain why. Try to answer before opening the solution.
-
var and setTimeout in a loop
What does this code print?
for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); }Show answer
Output (Node.js)
3 3 3var is function-scoped: the three callbacks share the same i, which is 3 by the time they run. With let, each iteration gets its own i and it would print 0, 1 and 2.
-
References and sort()
What does this code print?
const a = [1, 2, 3]; const b = a; b.push(4); console.log(a.length, [10, 1, 2].sort());Show answer
Output (Node.js)
4 [ 1, 10, 2 ]b points to the same array as a, so a now has 4 elements too. And sort() without a comparator sorts as strings: “10” comes before “2”. To sort numbers, use sort((x, y) => x - y).
-
Promises vs setTimeout
What does this code print?
console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')); console.log('D');Show answer
Output (Node.js)
A D C BSynchronous code runs first (A and D). Then microtasks, like a promise’s then (C), and finally tasks, like setTimeout (B), even with a 0 ms delay.
Practice with a mock interview
Knowing the answer isn’t enough: you have to explain it calmly in front of someone. In SyntaxQuest, Syntax plays the recruiter on a video call, asks you JavaScript questions for the role and your level (junior, mid-level or senior), grades the content of your answers and gives you feedback on your eye contact, pace and filler words. At the end, Syntax tells you whether you’d be hired.
Included in Pro. Nothing is recorded: the camera is analyzed on your iPhone.
JavaScript interview FAQ
What do they ask in a JavaScript technical interview?
Almost always: var, let and const, closures, this, promises and async/await, the event loop, array methods (map, filter, reduce) and the difference between == and ===. Frontend roles add the DOM and events; backend roles add Node.js.
Do I need TypeScript for a JavaScript interview?
It depends on the job, but it helps: TypeScript is JavaScript with types, so everything in this guide still applies. If the role asks for it, also review interfaces, generics and union types.
What’s the difference between JavaScript and Node.js?
JavaScript is the language; Node.js is a runtime that runs it outside the browser, on servers and in command-line tools. The language is the same, but the APIs differ: the browser has the DOM and window; Node.js has modules for files, processes and servers.
How do I prepare for a JavaScript interview?
Review the fundamentals, solve short exercises and, above all, answer out loud: explaining an idea clearly is harder than recognizing it. In SyntaxQuest you can review with the free JavaScript course and do video-call mock interviews with Syntax, included in Pro.
Does the mock interview record my camera?
No. Nothing is recorded: the camera is analyzed on your iPhone to give you feedback on eye contact, and Apple’s speech recognition transcribes your voice. Syntax only gets the text of your answer.