Expert · Interview preparation and career · topic 57 of 61 · 30 min
Core concept questions
Explanation
How to answer a concept question
- Define it in one sentence, in plain words.
- Show a 2–4 line example (write it on the whiteboard or type it).
- Give one real consequence or use ("that is why…", "we use it for…").
- Stop. Let the interviewer ask a follow-up instead of talking for five minutes.
Model answers
| Question | Short answer |
|---|---|
| What is a closure? | A function that remembers the variables of the scope where it was created, even after that scope has finished. Used for private state, counters, factories and callbacks. |
| What is hoisting? | Declarations are processed before code runs: function declarations are usable early, var is undefined early, let/const/class are in the temporal dead zone and throw. |
| How is this decided? | By how a function is called: obj.method() → obj; plain call → undefined in strict mode; new → the new object; call/apply/bind set it; arrows use the outer this. |
| == vs ===? | === compares type and value without conversion; == converts types first, with confusing rules. Use ===. |
| let vs const vs var? | let and const are block-scoped; const cannot be reassigned; var is function-scoped, hoisted as undefined and can be redeclared. Prefer const, then let. |
| null vs undefined? | undefined means a value was never given; null means empty on purpose. typeof null is "object" (a historic bug). |
| What is the prototype chain? | Objects link to a prototype object; property lookups walk up the chain until found or null. Classes put methods on the prototype. |
| What is the event loop? | One thread runs code from the call stack; when it is empty, all microtasks (promises) run, then one macrotask (timers, I/O), repeatedly. |
| Promise vs async/await? | async/await is syntax on top of promises; an async function returns a promise, and await pauses that function until a promise settles. |
| Shallow vs deep copy? | A shallow copy (spread) copies one level and shares nested objects; a deep copy (structuredClone) copies every level. |
Example: answering "What is a closure?" aloud
function makeCounter() {
let count = 0;
return () => ++count; // the arrow "closes over" count
}
const next = makeCounter();
next(); next(); // 2: count survives between callsFollow-up questions to expect
- Can closures cause memory leaks? (Yes, if a long-lived closure holds big data.)
- Why does a var loop with setTimeout print the same number? (One shared var; let creates one per iteration.)
- What does bind return? (A new function with this fixed; it does not call it.)
- What runs first: setTimeout 0 or Promise.then? (The promise callback, a microtask.)
- What is the difference between map and forEach? (map returns a new array; forEach returns undefined and is for side effects.)
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Core concept questions · 1/6
In this lesson you will practise answering the most common JavaScript concept questions.
Prefer a video by a teacher? Find free videos on “javascript interview questions closures hoisting event loop” on YouTube ↗
In real life: A typical first round at a product company
In a 45-minute first round for a front-end role at a Bengaluru start-up, the interviewer asked about closures, the event loop and this, each followed by "write a small example". Candidates who answered in two sentences and immediately typed a working example moved to the coding round; long theoretical answers without code did not.
// "Show me that promise callbacks run before timers"
setTimeout(() => console.log('timer'), 0);
Promise.resolve().then(() => console.log('promise'));
console.log('sync');
// sync, promise, timerPractice (0/2 done)
Answer these five questions ALOUD, each in under 45 seconds with a tiny example: (1) closure, (2) hoisting, (3) this in an arrow function, (4) == vs ===, (5) event loop order of setTimeout 0 vs Promise.then. Record yourself and listen back.
A classic follow-up: "fix this so the callbacks log 0, 1, 2". Change ONE keyword so that runAll() returns [0, 1, 2] instead of [3, 3, 3].
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Predict-the-output questionsInterview preparation and career · same module
- Classic coding questionsInterview preparation and career · same module
- Data-structure questions in JavaScriptInterview preparation and career · same module
- Scope, hoisting and closuresFrontend Web Development · JavaScript in depth
- C++ interview questions and how to answer themC++ Programming (modern C++ and DSA) · Competitive programming, interviews and careers
- Portfolio, projects and interviewsData Science, Machine Learning and AI · Ethics, privacy and careers
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What does [1, 2, 3].forEach(x => x * 2) return?
Answer: undefined
forEach always returns undefined; map returns a new array.
Which statement about const is TRUE?
Answer: The variable cannot be reassigned, but an object it holds can be changed
const locks the binding, not the object.
What is the best response when you do not know an answer?
Answer: Say you are not sure and reason aloud from what you know
Interviewers value honest reasoning.
typeof function () {} is…
Answer: "function"
Functions are objects, but typeof reports "function".
What is a closure?Related
Answer: A function together with the outer variables it remembers
A closure is a function plus the variables from where it was created, which stay alive as long as the function does.
const a = [1, 2, 3]; a[10] = 4; console.log(a.length) prints…Related
Which answer about std::move is correct?Related
Answer: It is a cast to an rvalue; the actual move happens in the move constructor or assignment
std::move itself does no work at run time.
What is a closure?Related
Answer: A function plus the variables from where it was created that it remembers
Closures keep access to the variables of the scope where the function was defined.
From Scope and closures
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Interview preparation and career” before its exam: Predict-the-output questions, Classic coding questions, Data-structure questions in JavaScript, Projects, portfolio and jobs.
- Module 12 exam: Interview preparation · 12 questions · 25 min, without help. 5 topics of this module still to finish first.
- 61 topics left in the course before the final exam.