guide · interview prep
JavaScript interview questions and answers
These are the JavaScript questions interviewers ask most often, from junior screens to senior rounds. Each answer is short enough to say out loud in an interview, with an example where it helps.
When you have these down, practise the full set by difficulty on skillzunos.
Core language
What is the difference between var, let and const?
var is function-scoped and hoisted with the value undefined. let and const are block-scoped and sit in the temporal dead zone until their declaration runs. const cannot be reassigned, but an object it points to can still be changed.
What is hoisting?
Declarations are processed before code runs. Function declarations are fully hoisted, so you can call them before they appear. var declarations are hoisted as undefined; let, const and class are hoisted but cannot be used before their line.
What is the difference between == and ===?
=== compares value and type without conversion. == converts types first, so 0 == "0" and null == undefined are true. Use === unless you specifically want null == undefined.
What is the difference between null and undefined?
undefined means a value was never assigned. null is an explicit “no value” that you set. typeof undefined is "undefined", and typeof null is "object", a long-standing quirk.
What are the primitive types?
string, number, bigint, boolean, undefined, symbol and null. Everything else, including arrays and functions, is an object. Primitives are compared and copied by value; objects by reference.
Functions, scope and this
What is a closure?
A function together with the variables from the scope it was created in. The inner function keeps access to them even after the outer function has returned. Closures power private state, factories and callbacks.
function counter() {
let n = 0;
return () => ++n;
}
const next = counter();
next(); // 1
next(); // 2How is this decided?
By how a function is called: as obj.method() this is obj; called plainly it is undefined in strict mode; with new it is the new object; with call, apply or bind it is what you pass. Arrow functions have no own this and use the surrounding one.
What do call, apply and bind do?
All three set this. call invokes the function with arguments listed one by one, apply with an array of arguments, and bind returns a new function with this (and optionally some arguments) fixed.
How are arrow functions different?
They have no own this, arguments or prototype, cannot be used with new, and are always anonymous expressions. Use them for callbacks; use regular functions for methods that need their own this.
Async JavaScript
How does the event loop work?
JavaScript runs one call stack. When it is empty, the event loop first runs all queued microtasks (promise callbacks, queueMicrotask), then takes one macrotask (a timer, an I/O or UI event), and repeats. That is why a resolved promise’s then runs before a setTimeout of 0.
setTimeout(() => console.log("timeout"));
Promise.resolve().then(() => console.log("promise"));
console.log("sync");
// sync, promise, timeoutWhat is a Promise?
An object for a value that will arrive later. It is pending, then either fulfilled or rejected, once. then and catch register what to do next and return new promises, so steps can be chained.
How does async/await relate to promises?
An async function always returns a promise, and await pauses that function until a promise settles, without blocking the thread. It is promise code written top to bottom; wrap awaits in try/catch to handle rejections.
Promise.all, allSettled, race and any?
all resolves when every promise fulfils and rejects on the first failure. allSettled waits for all and reports each result. race settles with the first to settle. any fulfils with the first success and rejects only if all fail.
Objects, arrays and the DOM
How does prototypal inheritance work?
Every object has a hidden link to a prototype object. When a property is not found on the object, JavaScript looks along that prototype chain. class syntax is a cleaner way to set up the same chain.
Shallow copy vs deep copy?
A shallow copy ({...obj}, Object.assign, arr.slice) copies the top level only; nested objects are still shared. structuredClone(obj) makes a deep copy of plain data.
map vs forEach?
map returns a new array of the callback results; forEach returns undefined and is used for side effects. Neither can be stopped early; use a for...of loop or some/every for that.
What is event delegation?
Attaching one listener to a parent instead of one per child. Events bubble up, so the parent checks event.target (often with closest()) to see which child was clicked. It saves memory and works for elements added later.
What are debounce and throttle?
Debounce waits until calls stop for a set time, then runs once: good for search-as-you-type. Throttle runs at most once per interval: good for scroll and resize handlers.
Frequently asked questions
What JavaScript topics are asked in interviews?
Scope and hoisting, closures, this, the event loop, promises and async/await, prototypes, array methods, copying objects, and DOM events like delegation. Senior rounds add performance, patterns and system design.
How should I prepare for a JavaScript interview?
Learn the core questions above until you can explain them out loud, write small examples for each, then practise questions by difficulty and do a mock interview.
Where can I practise more JavaScript interview questions?
skillzunos has JavaScript interview questions and tutorials by difficulty, plus TypeScript, React, Node.js, system design and more.