Back to Home

JavaScript Interview Questions

Master JavaScript fundamentals and ace your next technical interview. These are the most commonly asked JavaScript interview questions, covering everything from basics to advanced concepts. Practice these with SwipeInterview for the best results.

Easy

What is the difference between let, const, and var?

Answer: var is function-scoped and can be redeclared. let and const are block-scoped. const cannot be reassigned after declaration, while let can. Modern JavaScript prefers let and const for better scoping and to prevent accidental reassignments.

Easy

What is a closure in JavaScript?

Answer: A closure is a function that has access to variables in its outer (enclosing) lexical scope, even after the outer function has returned. Closures allow functions to "remember" and access variables from their creation context.

Medium

Explain the event loop in JavaScript

Answer: The event loop is JavaScript's concurrency model. It continuously checks the call stack and task queue. When the call stack is empty, it takes the first task from the queue and pushes it onto the stack for execution. This enables asynchronous operations in single-threaded JavaScript.

Medium

What is the difference between == and ===?

Answer: == performs type coercion before comparison, while === (strict equality) compares both value and type without coercion. For example, 5 == "5" is true, but 5 === "5" is false. Always prefer === to avoid unexpected behavior.

Medium

What is hoisting in JavaScript?

Answer: Hoisting is JavaScript's behavior of moving declarations to the top of their scope during compilation. Function declarations and var variables are hoisted (var is hoisted but not initialized). let and const are also hoisted but remain in a "temporal dead zone" until initialized.

Hard

Explain prototypal inheritance in JavaScript

Answer: JavaScript uses prototypal inheritance where objects can inherit properties from other objects. Every object has an internal [[Prototype]] property. When accessing a property, JavaScript first looks on the object itself, then walks up the prototype chain until it finds the property or reaches null.

Hard

What is the purpose of Promise.all() and Promise.race()?

Answer: Promise.all() takes an array of promises and returns a single promise that resolves when all promises resolve, or rejects if any promise rejects. Promise.race() returns a promise that resolves or rejects as soon as one of the promises in the array resolves or rejects.

Ready to Practice More?

Get access to 380+ JavaScript questions with SwipeInterview's interactive learning platform.

Start Practicing Now

More Interview Topics

React Questions Python Questions AWS Questions