What you'll learn
Quick Answer
Fresher JavaScript interviews concentrate on a small set of topics: var, let and const with hoisting, closures, the this keyword, == versus ===, the event loop and async behaviour, array methods, and prototypes. Answers that state the mechanism beat answers that recite a definition, and adding a short example of where it bites in real code is what separates a strong candidate from a memorised one.
Variables, Scope and Hoisting
What is the difference between var, let and const?
Answer with three axes rather than a list. var is function-scoped; let and const are block-scoped. All three are hoisted, but var is initialised to undefined while let and const sit in the temporal dead zone and throw if read early. const prevents reassignment, not mutation.
const arr = [1, 2];
arr.push(3); // fine — mutation
arr = [4]; // TypeError — reassignmentThat last distinction is a very common follow-up.
What is hoisting?
Declarations are registered before code runs, so the engine knows the names exist. Nothing physically moves. Say that, then give the contrast: reading a var early gives undefined, reading a let early throws a ReferenceError.
Why does this print 3, 3, 3?
for (var i = 0; i < 3; i++) setTimeout(() => console.log(i), 0);Because var is function-scoped, all three callbacks close over the same i, which is 3 by the time they run. let creates a fresh binding per iteration, giving 0, 1, 2. This is asked constantly.
Closures and this
What is a closure?
A function that keeps access to variables from the scope where it was defined, even after that scope has returned. Give a use rather than only a definition — data privacy is the classic:
function counter() {
let count = 0; // not reachable from outside
return () => ++count;
}
const next = counter();
next(); // 1
next(); // 2Good follow-up material: closures are why the var loop above misbehaves, and why event handlers can capture stale values.
What is this?
The key sentence: this is decided by how a function is called, not where it is defined. Then give the four rules — new, explicit binding with call/apply/bind, the object before the dot, and otherwise the global object or undefined in strict mode.
How do arrow functions differ?
They have no this of their own and inherit it from the enclosing scope, which is why they fix callbacks and break object methods.
const obj = { name: 'x', get: () => this.name }; // undefined — arrow in a literalThey also cannot be used with new and have no arguments object.
Equality, Types and Coercion
What is the difference between == and ===?
=== compares value and type with no conversion. == converts first, which produces results that look arbitrary:
0 == '0' // true
0 == [] // true
'0' == [] // false — the three together surprise people
null == undefined // true
null === undefined // false
NaN == NaN // falseSay you default to ===, and that the one common use of == is x == null to catch both null and undefined in a single check.
What are the data types in JavaScript?
Seven primitives — string, number, boolean, undefined, null, symbol, bigint — plus objects, which include arrays and functions.
Why does typeof null return "object"?
A bug from the earliest implementation, kept because fixing it would break the web. A good answer notes it is why typeof alone cannot distinguish null from an object.
What is the difference between undefined and null?
undefined means never assigned — the engine's default. null means deliberately empty — your assignment. Both are falsy.
Asynchronous JavaScript
What is the event loop?
JavaScript runs on one thread with one call stack. Async work is handed to the browser or Node, which queues a callback when it finishes. The event loop moves queued callbacks onto the stack when the stack is empty.
What will this print?
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');
// 1, 4, 3, 2Explain why: synchronous code first, then the microtask queue is drained completely, and only then a macrotask. Promises are microtasks and always beat setTimeout, regardless of order in the source. This single question separates memorisation from understanding.
What is a promise?
An object representing a value that is not available yet, in one of three states — pending, fulfilled, rejected. It replaces nested callbacks with a chain, and async/await is syntax over the same mechanism.
What is callback hell and how do you avoid it?
Deeply nested callbacks that become unreadable. Avoid with promises and async/await. Mention that awaits inside a loop run sequentially, and Promise.all runs them in parallel — a practical detail interviewers like.
Arrays, Objects and the DOM
Difference between map, filter and forEach?
map returns a new array of the same length with transformed values. filter returns a shorter array of items passing a test. forEach returns undefined and exists only for side effects. A common trap: using map when you ignore the result — that should be forEach.
How do you copy an object?
Spread or Object.assign for a shallow copy, structuredClone for a deep one. Be ready to explain that spread copies one level and nested objects stay shared.
What is the difference between slice and splice?
slice returns a portion and does not modify the original. splice changes the array in place and returns the removed items. The mnemonic that sticks: splice splices the original.
What is event bubbling and delegation?
An event fires on the target then bubbles up through its ancestors. Delegation exploits that by putting one listener on a parent instead of many on children — better for performance and it works for elements added later.
list.addEventListener('click', e => {
if (e.target.matches('li')) handle(e.target);
});What is prototypal inheritance?
Objects inherit from other objects through the prototype chain. When a property is missing, JavaScript follows the chain upward until it finds it or reaches null. class is syntax over this, not a different model.
