
5 Interview Questions About JavaScript, Answered with Code
The interview questions about JavaScript that decide most screening rounds are the difference between == and ===, closures, hoisting, the this keyword, and the event loop. If you are a fresher, get the first three solid and you will clear most first rounds. If you have two or more years of experience, expect the last two, usually with a code snippet you must trace out loud.
Most question lists run to 50 or 100 items, and you end up memorizing definitions you cannot explain. Interviewers notice. They are rarely checking whether you know a term. They want to hear why the language behaves the way it does, and whether you can predict output without running the code.
This guide covers the five questions that carry the most weight. Each one gives a short answer you can say aloud, a code example, and the follow-ups that usually come next. Olibr is a recruiting platform used by tech recruiters hiring developers in India, so the framing here is the one screening interviews tend to use.
1. What is the difference between == and ===?
Short answer

The == operator compares values after converting them to a common type. The === operator compares value and type with no conversion. This is the opening question in many interview questions about JavaScript because it tests whether you understand type coercion. Use === by default, and use == only for a deliberate check such as value == null, which matches both null and undefined.
Strict equality never guesses, and loose equality always does.
Code example
Be ready to evaluate these lines in your head, because interviewers often hand you a list like this.
0 == "" // true
"5" == 5 // true
null == undefined // true
null === undefined // false
NaN === NaN // false
3 + 2 + "7" // "57"
The last line is a favorite. Addition runs left to right, so 3 + 2 becomes 5 first, and then 5 joins the string to give "57".
Follow-up questions to expect
Once you answer this one, the interviewer usually tests your grasp of types.
- What are the primitive types? String, number, bigint, boolean, undefined, null, and symbol.
- Why does
typeof nullreturn "object"? It is a long-standing bug in the language that was never fixed. - How do you check for NaN? Use
Number.isNaN(x)orObject.is(x, NaN), sinceNaN === NaNis false.
2. How do closures work in JavaScript?
Short answer

A closure is a function that remembers the variables from the scope where it was created, even after that outer function has finished running. Interviewers love this topic because closures sit behind callbacks, event handlers, and the module pattern. Say it plainly: the inner function keeps a live reference to the outer variables, not a copy.
A closure is a function carrying its birthplace with it.
Code example
The classic demonstration is a counter with private state.
function makeCounter() {
let count = 0;
return () => ++count;
}
const next = makeCounter();
next(); // 1
next(); // 2
Nothing outside can touch count. That is data privacy without classes, and it is the point to make out loud when you answer these interview questions about JavaScript.
Follow-up questions to expect
Expect the interviewer to push on the edges of the idea.
- Why does a
varloop withsetTimeoutprint the same number? All callbacks share onevarvariable. Usingletcreates a fresh binding per iteration. - Can closures cause memory leaks? Yes, if a long-lived closure holds a reference to something large that you no longer need.
- Where do you use closures in real code? Debounce functions, memoization, and factory functions.
3. What is hoisting in JavaScript?
Short answer

Hoisting means that JavaScript registers declarations before it runs any code in a scope. Function declarations are fully available early. A var variable exists early but holds undefined. Variables declared with let and const are also registered, yet they sit in the temporal dead zone until their line runs, so reading them early throws a ReferenceError.
Declarations move up, but assignments never do.
Code example
This snippet separates the three behaviors cleanly, and it is a common whiteboard item in interview questions about JavaScript.
console.log(a); // undefined
var a = 5;
greet(); // "hi" (function declarations are fully hoisted)
function greet() { console.log("hi"); }
console.log(b); // ReferenceError (temporal dead zone)
let b = 10;
Mention that a function expression such as var sayHi = function () {} is not hoisted as a function. Calling it early throws a TypeError, because sayHi is still undefined.
Follow-up questions to expect
Hoisting questions almost always lead into variable declarations.
- What is the difference between
var,let, andconst?varis function scoped.letandconstare block scoped, andconstcannot be reassigned. - Can you change a
constobject? Yes. You cannot rebind the variable, but you can mutate the object's properties.
4. How does the this keyword work?
Short answer
The value of this is decided by how a function is called, not where it is written. A method call uses the object before the dot. A plain call gives the global object, or undefined in strict mode. The new keyword binds a fresh object. Arrow functions are the exception, because they take this from the surrounding scope.
Ask who called the function, and you have the value of this.
Code example
The bug that interviewers show most often is a method that loses its object.
const user = {
name: "Asha",
greet() { return this.name; }
};
user.greet(); // "Asha"
const fn = user.greet;
fn(); // this is no longer user
const bound = user.greet.bind(user);
bound(); // "Asha"
Pulling the method out of the object removes the call-site context. bind fixes it by locking this permanently. This is one of the interview questions about JavaScript where a clear fix earns more credit than the definition.
Follow-up questions to expect
You will likely be asked to compare the three explicit binding tools.
- What is the difference between
call,apply, andbind?callandapplyinvoke the function immediately, with arguments passed separately or as an array.bindreturns a new function. - Why use arrow functions inside callbacks? They keep the outer
this, so you avoid saving it in a variable.
5. How does the JavaScript event loop work?
Short answer
JavaScript runs on a single thread with one call stack. Asynchronous work is handed to the browser or Node.js, and finished callbacks wait in queues. The event loop moves them onto the stack only when it is empty. Promise callbacks (microtasks) always run before timer callbacks (macrotasks), which explains most output-order puzzles among interview questions about JavaScript.
Microtasks cut the line ahead of timers, every single time.
Code example
Predict the order before you read the answer.
console.log("1");
setTimeout(() => console.log("2"), 0);
Promise.resolve().then(() => console.log("3"));
console.log("4");
// Output: 1, 4, 3, 2
Synchronous lines print first, which gives 1 and 4. The promise callback then runs as a microtask. The zero-delay timer prints last, because it waits in the macrotask queue.
Follow-up questions to expect
Event loop answers open the door to asynchronous patterns.
- What are the states of a promise? Pending, fulfilled, and rejected.
- How does
async/awaitrelate to promises? It is syntax built on promises, andawaitpauses only the async function, not the thread. - What is debouncing? It delays a function until calls stop for a set time, which is common for search boxes.
Where to go from here
Five questions will not cover every interview, but they cover the reasoning that interviewers test in all the others. Practice each one aloud, trace the code by hand, and be ready to explain why the output happens, not only what it is.
Once your answers are steady, put them to use. Browse live roles, apply directly, and get ready for your next round through open developer and tech jobs in India.
For engineers
Find work worth your time.
Live engineering roles across India and the US, matched to your stack. Build a profile recruiters actually discover.