Once the basics are covered, senior JavaScript interviews move to the parts of the language most developers never touch directly — but rely on every day through libraries and frameworks. This guide covers generators, iterators, Symbols, Proxy and Reflect, deep copying, memory leaks and strict mode.
Why interviewers ask about advanced JavaScript
These features sit underneath the tools you already use: Vue's reactivity is built on Proxy, for...of and spread run on iterators, and many state libraries depend on correct copying. Interviewers ask about them to see whether you can reason about the platform rather than only follow examples.
For experienced roles, the interviewer also wants judgement — when a Proxy is worth its cost, why a deep copy is lossy, how you would track down a memory leak in production.
How to answer these questions
Answer at two levels: what the feature does in one sentence, then where you have seen it used. "Vue 3 tracks state changes with a Proxy set trap" turns an abstract API into something concrete.
Most of these build on objects and prototypes, so the OOP and prototypes guide is useful background, and the browser and performance guide pairs naturally with the memory-leak question.
Q1. What are generator functions?
Generators are functions declared with function* that can pause and resume with yield. Calling one returns an iterator, and each next() runs the body until the next yield.
function* idGen() {
let id = 1;
while (true) {
yield id++;
}
}
const gen = idGen();
gen.next().value; // 1
gen.next().value; // 2
gen.next().value; // 3
They are used for lazy and infinite sequences and to model asynchronous flows (as in redux-saga).
Q2. What are iterators and iterables?
An iterable is any object with a [Symbol.iterator]() method that returns an iterator. An iterator is an object with a next() method that returns { value, done }. Iterables work with for...of and spread.
const range = {
from: 1, to: 5,
[Symbol.iterator]() {
let current = this.from;
const last = this.to;
return {
next() {
return current <= last
? { value: current++, done: false }
: { value: undefined, done: true };
},
};
},
};
[...range]; // [1, 2, 3, 4, 5]
Q3. What is the Symbol primitive type?
Symbol() creates a guaranteed-unique value. Symbols make property keys that never collide with other keys, and well-known symbols such as Symbol.iterator let objects plug into language features.
const id = Symbol("id");
const user = { [id]: 42, name: "Siva" };
user[id]; // 42
user.id; // undefined — the symbol key is separate
// Well-known symbol
class MyList {
[Symbol.iterator]() {
let i = 0, data = [1, 2, 3];
return { next: () => ({ value: data[i++], done: i > data.length }) };
}
}
[...new MyList()]; // [1, 2, 3]
Q4. What is a Proxy in JavaScript?
A Proxy wraps an object and intercepts basic operations — get, set, delete and more — through handler functions called traps. It is used for validation, logging and reactivity systems such as Vue 3.
const handler = {
get(target, key) {
return key in target ? target[key] : `Key "${key}" not found`;
},
set(target, key, value) {
if (typeof value !== "number") throw new TypeError("Numbers only");
target[key] = value;
return true;
},
};
const obj = new Proxy({}, handler);
obj.score = 95;
obj.score; // 95
obj.missing; // 'Key "missing" not found'
Q5. What is the Reflect API?
Reflect is a built-in object whose methods mirror the basic object operations — Reflect.get, Reflect.set, Reflect.has, Reflect.ownKeys and more. It is most often used inside Proxy traps to perform the default behaviour.
const logged = new Proxy({ a: 1 }, {
get(target, key, receiver) {
console.log(`read ${String(key)}`);
return Reflect.get(target, key, receiver); // default behaviour
},
});
logged.a; // logs "read a", returns 1
Reflect.ownKeys({ x: 1, [Symbol("id")]: 2 }); // ["x", Symbol(id)]
Reflect methods report failure with return values instead of exceptions — Reflect.set returns false when an assignment fails, where a plain assignment would throw in strict mode.
Q6. What is the difference between a shallow copy and a deep copy?
A shallow copy duplicates only the top-level properties, so nested objects are still shared. A deep copy duplicates every nested value, giving a fully independent clone.
const obj = { a: 1, b: { c: 2 } };
// Shallow copy — b is still shared
const shallow = { ...obj };
shallow.b.c = 99;
obj.b.c; // 99 (mutated!)
// Deep copy
const deep = JSON.parse(JSON.stringify(obj)); // simple but lossy
const deep2 = structuredClone(obj); // modern, preferred
Interview note: Trap: "what does the JSON trick lose?" Functions,
undefinedvalues,Dateobjects (they become strings),Map/Setand circular references.structuredClonehandles dates, maps, sets and cycles.
Q7. What causes memory leaks in JavaScript and how do you find them?
JavaScript frees memory automatically once nothing references it, so leaks come from references you forgot about: listeners and timers that are never removed, detached DOM nodes still held in variables, caches that only grow, and accidental globals. Find them in the Memory panel of Chrome DevTools by comparing heap snapshots.
// Leak: the interval keeps running and holds `data` forever
function start() {
const data = new Array(1e6).fill("x");
setInterval(() => console.log(data.length), 1000);
}
// Fix: keep the id and clear it when done
const id = setInterval(tick, 1000);
clearInterval(id);
// Fix for listeners: remove what you add
el.addEventListener("scroll", onScroll);
el.removeEventListener("scroll", onScroll);
Interview note: Follow-up: "how does garbage collection decide what to free?" Modern engines use mark-and-sweep: starting from roots such as globals and the call stack, everything reachable is kept and the rest is freed.
Q8. What is strict mode in JavaScript?
Strict mode ("use strict") is an opt-in, safer variant of JavaScript: assigning to an undeclared variable throws instead of creating a global, this is undefined in plain function calls, duplicate parameter names are errors, and silent failures become exceptions.
"use strict";
total = 10; // ReferenceError — no accidental global
function show() { return this; }
show(); // undefined (the global object without strict mode)
const obj = Object.freeze({ x: 0 });
obj.x = 1; // TypeError instead of silently doing nothing
ES modules and class bodies are always strict, so most modern code already runs in strict mode without the directive.
How to prepare
Implement a few of these from scratch: a custom iterable range, a generator-based ID maker, a validation Proxy, and a deep-clone function that handles nested arrays and dates. Then take a heap snapshot of a page with a deliberate leak and find it in DevTools.
For broader interview practice, return to the JavaScript basics guide for a quick refresh, or see the JavaScript developer roadmap for what senior roles expect.
Frequently Asked Questions
What JavaScript questions are asked for experienced developers?
What is the difference between a generator and an async function?
When would you use a Proxy in real code?
Is structuredClone supported everywhere?
How does garbage collection work in JavaScript?
Should I write "use strict" in every file?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — Explore the Java Full Stack program

