100+ JavaScript Interview Questions & Answers for 2026
The ultimate guide to acing your JavaScript interviews. From closures and event loops to 100+ rapid-fire questions.
100+ JavaScript Interview Questions
The definitive guide. From simple data types to complex microtask queues, mastering these 100+ questions will separate you from 90% of candidates.

Let's be real-JavaScript interviews can be brutal. You think you know the language, then someone asks you to explain the output of a tricky closure loop or how the microtask queue really works.
In the world of modern web development, the difference between a junior developer and a senior engineer often comes down to deep theoretical understanding. It's not just about writing code; it's about knowing how the code executes.
This isn't just a list of questions copied from a textbook. This is a collection of real-world questions, practical scenarios, and "gotchas" that are frequently asked in technical interviews. Whether you're aiming for a role at a top-tier tech company or a fast-paced startup, mastery of these topics is essential.
How to use this guide
JavaScript Fundamentals
What are the data types in JavaScript? Explain each with examples.
JavaScript is a dynamically typed language, meaning you don't need to define the type of a variable usually. There are 8 standard data types in the latest ECMAScript standard.
1. Primitives (Immutable)
Represents textual data.
const name = "Dev";Integers & floats. (Max: ±2^53 - 1).
let age = 25;For large integers > 2^53 - 1. Suffix n.
const big = 900n;Logical entity.
true / falseVariable declared but not assigned.
Intentional absence of any object value.
Unique, immutable identifier for object properties.
const id = Symbol('id');2. Non-Primitive (Reference)
Used to store keyed collections of varying data and more complex entities. Includes Arrays, Functions, Dates, etc.
const user = { name: "Dev" };The 'typeof null' Bug
typeof null returns "object". This is a historical bug in JavaScript. Correct check: value === null.Explain var vs let vs const in depth.
Before ES6 (2015), var was the only way to declare variables. let and const were introduced to fix issues with hoisting and scope leakage.
- Scope: Function
- Hoisting: Yes (undefined)
- Reassign: Yes
- Redeclare: Yes
- Scope: Block
{} - Hoisting: TDZ*
- Reassign: Yes
- Redeclare: No
- Scope: Block
{} - Hoisting: TDZ*
- Reassign: No
- Redeclare: No
*TDZ (Temporal Dead Zone): The time between entering the scope and the actual variable declaration.
What is Hoisting? Declaration vs Expression?
Hoisting moves declarations to the top of the scope.
Fully hoisted. Can be called before definition.
Variable hoisted as undefined. Assignment stays.
Explain Type Coercion and Equality (== vs ===).
Implicit Coercion happens when operators convert types automatically.
Coercion Examples
- '2' + 2 '22'
- '2' - 2 0
- true + 1 2
Equality check
- 0 == false true
- 0 === false false
- null == undefined true
Rule of thumb
=== (Strict) unless checking for null/undefined specifically.What are Truthy and Falsy values?
Values that resolve to true or false in boolean contexts.
Functions & Scope
Deep Dive: What is a Closure? Why is it powerful?
A Closure is created when a function is defined inside another function, allowing the inner function to access the outer function's variables-even after the outer function has finished executing.
Core Concept
Inner functions contain the scope of parent functions even if the parent has returned.
Closures are often used to emulate private variables (Module Pattern).
Interview Analogy
Output Challenge: The Loop Closure Trap
This is a classic interview favorite. It tests your understanding of var (function scope) vs let (block scope) inside loops.
var i is shared across all iterations. By the time setTimeout runs, the loop has finished and i is 3.
let i creates a new binding (new i) for each iteration of the loop.
Explain Call, Apply, and Bind. When to use which?
These methods allow you to explicitly set the value of this for a function.
Invokes function immediately.
Args: Comma separated (this, arg1, arg2)
Invokes function immediately.
Args: Array (this, [arg1, arg2])
Returns a new function.
Does not execute immediately. Useful for events.
What is Currying? Write a curry function.
Currying is the process of transforming a function that takes multiple arguments into a sequence of functions that each take a single argument.f(a, b, c) becomes f(a)(b)(c).
What is an IIFE (Immediately Invoked Function Expression)?
A function that runs as soon as it is defined. Before ES6 Modules, this was the primary way to create module patterns and avoid polluting the global namespace.
Async JS & The Event Loop
Critical Context
How does the Event Loop actually work? (Microtasks vs Macrotasks)
The Event Loop is the mechanism that allows JS to perform non-blocking operations. It coordinates the execution of code between the Call Stack and various Queues.
1. Call Stack
LIFO (Last In, First Out). Where your synchronous code runs.
2. Web APIs
Where browser handles async things (DOM events, fetch, setTimeout).
3. Microtask Queue
High Priority. Promises (`.then`), `queueMicrotask`, MutationObserver.
4. Task Queue (Macrotask)
Low Priority. `setTimeout`, `setInterval`, `setImmediate`.
Output Challenge: Async Priority
Predict the order of logs. Remember: Sync > Microtask > Macrotask.
Explain Promise.all vs allSettled vs race vs any
Modern JS provides powerful concurrency methods for handling multiple promises.
"All or Nothing"
- Resolves when all resolve.
- Rejects immediately if one rejects.
"Wait for Everyone"
- Waits for all to finish (success or fail).
- Returns array of objects `{ status, value/reason }`.
"First One Wins"
- Settles as soon as the first promise settles (resolves OR rejects).
"First Success Wins"
- Resolves as soon as the first promise fulfills.
- Rejects only if all reject (AggregateError).
What is Async/Await and how does error handling work?
async/await is syntactic sugar built on top of Promises. It makes asynchronous code look and behave like synchronous code.
- An
asyncfunction always returns a Promise. awaitpauses the execution of its surrounding async function until the Promise settles.- It does not block the main thread (Call Stack).
Objects & Prototypes
What is the Prototype Chain? Explain Prototypal Inheritance.
JavaScript is prototype-based, not class-based (classes are just syntactic sugar). Every object has a hidden property [[Prototype]] (accessed via __proto__) that points to another object.
The Chain Lookup
Performance
null is reached.How does 'this' work? (The 4 Rules)
The value of this depends on how the function is called, not where it is defined.
Called with a dot obj.func().
this = objUsing call, apply, bind.
this = argument passedCalled with new keyword.
this = new empty objectStandalone call func().
this = window / undefinedthis. They inherit it from the surrounding (lexical) scope.What is the difference between Shallow Copy and Deep Copy?
Copying objects in JS can be tricky because simple assignment (=) only copies the reference, not the value.
Shallow Copy
Copies the top-level properties. Nested objects are still references (shared).
Deep Copy
Creates a completely independent clone, including all nested objects.
ES6+ Modern Features
Explain ES6 Classes and how they differ from the prototype method.
Classes in JS are "syntactic sugar" over the existing prototype-based inheritance. They provide a cleaner, more familiar syntax for creating objects and dealing with inheritance.
Features
- Constructor: Special method for initialization.
- Super: Calls parent constructor/methods.
- Static: Methods called on the class, not instances.
- Getters/Setters: Encapsulate property access.
Under the Hood
class Animal remains a function.
Methods defined in the class are added to Animal.prototype.
What are ES6 Modules? (Import / Export)
Modules allow splitting code into separate files. They rely on import and export statements. They run in strict mode automatically.
export const add = ...Import with curly braces: import { add } from './math'
export default UserImport without braces, any name: import User from './user'
Difference between ?? (Nullish Coalescing) and || (Logical OR)
A common bug source. || falls back on Falsy (0, "", false), whereas ?? falls back only on Nullish (null, undefined).
More ES6+ Essentials
Advanced Concepts
Explain Debouncing vs Throttling. When to use each?
Both techniques limit the rate at which a function gets called. They're crucial for performance optimization.
Debouncing
Waits for a pause in events before executing. Perfect for search inputs, auto-save.
User types: a- b- c- [pause] → Function runsThrottling
Guarantees execution at most once per time period. Ideal for scroll events, button clicks.
User scrolls: ✅- ❌- ❌- ❌- ✅- ❌What is Memoization? Implement a memoize function.
Memoization is an optimization technique that stores the results of expensive function calls and returns the cached result when the same inputs occur again.
When to Memoize
Explain common JavaScript Design Patterns.
Design patterns are reusable solutions to commonly occurring problems. In JavaScript interviews, knowing these shows you understand software architecture.
Module Pattern
Encapsulates private data and exposes public API using closures and IIFE.
Observer Pattern
Defines a one-to-many dependency between objects. When one object changes state, all dependents are notified.
Factory Pattern
Creates objects without specifying the exact class. Useful for creating similar objects with different configurations.
What are common causes of Memory Leaks in JavaScript?
Memory leaks occur when your application retains references to objects that are no longer needed, preventing garbage collection.
window.leak = largeObjectsetInterval without clearIntervalRemoved elements with JS referencesOuter scope references in callbacksReact Native Context
What is Event Delegation and why is it important?
Event delegation is a technique where instead of adding event listeners to multiple child elements, you add a single listener to a parent element and use event bubbling to handle events.
❌ Without Delegation
- • 100 buttons = 100 event listeners
- • Higher memory usage
- • Dynamic elements need new listeners
✅ With Delegation
- • 100 buttons = 1 event listener
- • Better performance
- • Works with dynamic elements
Output-Based Challenges
Pro Tip
🏆 Challenge 1: The Classic Var Loop
This question has eliminated countless candidates. Test your understanding of var scoping vs let block scoping.
What's the Output?
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}Answer & Explanation
3, 3, 3
var i is function-scoped and shared across all iterations. By the time setTimeout callbacks run, the loop has finished and i equals 3.
🏆 Challenge 2: Hoisting Madness
This tests your understanding of hoisting for variables, function declarations, and function expressions.
What's the Output?
console.log(a);
console.log(b);
console.log(c);
var a = 1;
let b = 2;
const c = 3;
function d() { return 4; }
var e = function() { return 5; };
console.log(d());
console.log(e());Answer & Explanation
undefined
ReferenceError
ReferenceError
4
TypeError
- var a is hoisted as undefined
- let b, const c are in TDZ
- Function d is fully hoisted
- Function expression e is undefined
🏆 Challenge 3: Event Loop Priority Puzzle
Test your understanding of the Event Loop, microtasks vs macrotasks, and execution order.
What's the Output?
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
Promise.resolve().then(() => {
console.log('4');
setTimeout(() => console.log('5'), 0);
});
console.log('6');Answer & Execution Order
1, 6, 3, 4, 2, 5
🔄 Sync: 1, 6 (immediate)
📋 Microtasks: 3, 4 (Promise resolves)
🗂️ Macrotasks: 2 (setTimeout)
🔄 New Microtask: 5 (from Promise in microtask)
🏆 Challenge 4: The 'this' Keyword Maze
This tests the 4 rules of this binding and how arrow functions change the game.
What's the Output?
const obj = {
name: 'Dev',
regular: function() {
console.log(this.name);
},
arrow: () => {
console.log(this.name);
},
nested: {
name: 'Nested',
regular: function() {
console.log(this.name);
},
arrow: () => {
console.log(this.name);
}
}
};
const standalone = obj.regular;
obj.regular();
standalone();
obj.arrow();
obj.nested.regular();
obj.nested.arrow();Answer & 'this' Analysis
"Dev"
undefined
undefined
"Nested"
undefined
1️⃣ obj.regular() - Implicit: this = obj
2️⃣ standalone() - Default: this = undefined (strict mode)
3️⃣ obj.arrow() - Arrow: inherits lexical this
4️⃣ obj.nested.regular() - Implicit: this = nested
5️⃣ obj.nested.arrow() - Arrow: inherits lexical this
🏆 Challenge 5: Advanced Closure Counter
This tests closure understanding with functions returning functions that maintain state.
What's the Output?
function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
reset: () => count = 0,
getValue: () => count
};
}
const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.getValue());
console.log(counter2.getValue());
counter1.reset();
console.log(counter1.getValue());
console.log(counter2.getValue());Answer & Closure Analysis
2
1
0
1
🧠 Each createCounter() creates independent closure
📊 counter1 increments to 2
📊 counter2 increments to 1 (separate from counter1)
🔄 counter1.reset() affects only counter1
📊 counter2 remains at 1
How to Approach Output Questions
- Identify the concept being tested (closures, hoisting, event loop, etc.)
- Mental execution - trace the code step by step
- Consider edge cases - what happens with undefined, null, etc.
- Explain the 'why' - interviewers want your reasoning, not just the answer
Bonus Materials
Quick Reference Cheat Sheet
Data Types
This Binding
Event Loop
Common Real World Interview Questions
React Native Focus
- •"Implement debounce for search input in React Native"
They wanted useCallback and optimization discussion
- •"Why does this useEffect cause infinite re-renders?"
Missing dependencies or incorrect closure usage
JavaScript Deep Dive
- •"Write Promise.race() from scratch"
Testing Promise understanding and async patterns
- •"Optimize this React component for performance"
Memo, useCallback, useMemo in action
What's Next? Your Learning Path
Immediate Next Steps (This Week)
- 1Master the Event Loop (draw it daily)
- 2Practice 10 output questions
- 3Implement 3 array polyfills
- 4Find a study partner
Advanced Topics (Next Month)
- React.js Interview Questions
- React Native Specific Topics
- TypeScript Advanced Patterns
- System Design for Mobile Apps
You've Got This!
Remember, every senior developer was once a junior struggling with closures and the event loop. The difference isn't talent - it's consistency. Study a little every day, draw concepts, explain them to others, and practice relentlessly.
"The best time to plant a tree was 20 years ago. The second best time is now." - Chinese Proverb
Ready to Ace Your Interview?
You've just covered 100+ JavaScript interview questions that differentiate junior developers from senior engineers. From fundamental data types to complex event loop mechanics, you now have the knowledge that gets you hired.
Continue Your Learning Journey
React.js Interview Guide
Hooks, Virtual DOM, Performance, State Management - Everything you need for React interviews.
React Native Guide
Native modules, Performance optimization, Platform-specific code - Mobile development mastery.
System Design
Scalability, Database design, Caching, Architecture patterns for senior roles.
Your Journey Starts Now
Knowledge is useless without application. Practice these concepts, build projects, contribute to open source, and most importantly - never stop learning. The tech world waits for no one, but it rewards those who persist.
"The expert in anything was once a beginner. The difference is persistence, not talent."
Frequently Asked Questions
How long should I study?
Dedicate 1-2 hours daily for 2-3 weeks. Focus on understanding concepts, not memorizing.
Are these questions outdated?
Updated for 2026. JavaScript fundamentals don't change much, but I've included ES2021+ features.
Can I use this for React interviews?
Absolutely! React is built on JavaScript. Understanding these fundamentals is crucial for React interviews.
Where can I practice more?
I highly recommend building small projects. Try implementing a debounced search bar or a deep clone function in a real app.
One Final Word
Remember, interviews are conversations, not interrogations. Be yourself, show your thought process, and don't be afraid to say "I don't know, but here's how I'd figure it out." That's what senior developers do every day.
Build a Consistent Coding Habit
Stop guessing and start building. This e-book provides practical strategies, exercises, and routines to help you code regularly and improve steadily.
Get E-BookMaster Unfamiliar Codebases
Struggling to make sense of someone else's code? Learn practical strategies to navigate, analyze, and master unfamiliar codebases with confidence.
Get E-Book
💬 Discussion