Skip to content

Expert · Interview preparation and career · topic 57 of 61 · 30 min

Core concept questions

Explanation

Most JavaScript interviews start with concept questions: closures, hoisting, this, == versus ===, prototypes, the event loop, var/let/const, null versus undefined. A strong answer is short: a one-line definition, a tiny example, and one practical consequence. Practise saying them aloud.

How to answer a concept question

  1. Define it in one sentence, in plain words.
  2. Show a 2–4 line example (write it on the whiteboard or type it).
  3. Give one real consequence or use ("that is why…", "we use it for…").
  4. Stop. Let the interviewer ask a follow-up instead of talking for five minutes.

Model answers

QuestionShort 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

javascript
function makeCounter() {
  let count = 0;
  return () => ++count;   // the arrow "closes over" count
}
const next = makeCounter();
next(); next();           // 2: count survives between calls
"A closure is a function plus the variables it remembers from where it was created. Here count lives on after makeCounter returns. We use this for private state, like a rate limiter."

Follow-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.)
Careful: Do not memorise definitions you cannot explain. Interviewers almost always ask "why?" or "show me". If you do not know something, say so honestly and reason aloud ("I think it works like this, because…"). Guessing confidently and being wrong hurts more than an honest "I am not sure".
Think of it like this: A good interview answer is like a good railway announcement: what (train 12951), where (platform 4), when (10:30). Short, clear, and the details come only if someone asks at the enquiry counter.
Tip: Record yourself answering five questions on your phone. Listen once. You will immediately hear where you ramble or where the example is missing.

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

Concept questions

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.

javascript
// "Show me that promise callbacks run before timers"
setTimeout(() => console.log('timer'), 0);
Promise.resolve().then(() => console.log('promise'));
console.log('sync');
// sync, promise, timer

Practice (0/2 done)

Task 1 · Practice

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.

Task 2 · Code · Javascript

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

Question 1

1.What does [1, 2, 3].forEach(x => x * 2) return?

Question 2

2.Which statement about const is TRUE?

Question 3

3.What is the best response when you do not know an answer?

Question 4

4.typeof function () {} is…

Read more (free)

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.

From Scope, hoisting and closures

const a = [1, 2, 3]; a[10] = 4; console.log(a.length) prints…Related

Answer: 11

Setting index 10 makes the length 11 (with empty slots).

From Predict-the-output questions

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.

From C++ interview questions and how to answer them

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

  1. 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.
  2. Module 12 exam: Interview preparation · 12 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. 61 topics left in the course before the final exam.

← Previous: Real project tooling