🟨 JavaScript Interview Questions

Master JavaScript interviews with questions on closures, promises, async/await, and ES6+ features

15-Minute JavaScript Cheatsheet

Quick reference for last-minute interview preparation

🎯 Core Concepts

Hoisting: var/functions moved to top
Closure: Function + lexical environment
Scope: Global, Function, Block (let/const)
this: Context depends on how called
Event Loop: Call stack + callback queue

✨ ES6+ Features

let/const - Block scoped variables
arrow => - Lexical this binding
... - Spread/rest operator
`template` - Template literals
destructuring - Extract values

⏳ Async JavaScript

Callbacks: Functions passed as arguments
Promises: .then(), .catch(), .finally()
async/await: Syntactic sugar for promises
Promise.all: Parallel execution
Promise.race: First to resolve/reject

📦 Objects & Arrays

map/filter/reduce - Array methods
Object.keys/values/entries
Object.assign/spread - Merge
JSON.parse/stringify
Deep vs Shallow: Copy methods

🔗 Prototypes & Classes

Prototype Chain: Inheritance mechanism
__proto__ - Object's prototype
class - Syntactic sugar
extends - Class inheritance
super - Parent reference

🌐 DOM & Events

Event Bubbling: Child to parent
Event Capturing: Parent to child
addEventListener
preventDefault/stopPropagation
Event Delegation: Single parent handler

⚠️ Common Interview Gotchas

• == vs === (type coercion)
• var hoisting vs let/const TDZ
• this in arrow vs regular functions
• Pass by value vs reference
• typeof null === 'object'
• NaN !== NaN (use Number.isNaN)

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

Easy

var, let, and const are used for variable declaration but have different scoping and hoisting behaviors.

javascript

Explain closures in JavaScript with examples

Medium

A closure is a function that remembers its lexical scope even when executed outside that scope. It "closes over" its outer variables.

javascript

Explain the event loop in JavaScript

Hard

The event loop is JavaScript's mechanism for handling asynchronous operations. It continuously checks the call stack and processes callbacks from the task queue.

javascript

What is 'this' keyword and how does it work?

Medium

this refers to the execution context. Its value depends on how a function is called, not where it's defined.

javascript

Explain Promises and async/await

Medium

Promises represent eventual completion of async operations. async/await is syntactic sugar that makes async code look synchronous.

javascript

What is prototypal inheritance in JavaScript?

Hard

JavaScript uses prototypal inheritance where objects inherit directly from other objects through the prototype chain.

javascript

Explain == vs === and type coercion

Easy

== performs type coercion before comparison, while === checks both value and type without coercion.

javascript

What are higher-order functions? Explain map, filter, reduce

Medium

Higher-order functions take functions as arguments or return functions. map, filter, and reduce are essential array methods.

javascript

What is event delegation and bubbling?

Medium

Event bubbling is when events propagate from child to parent. Event delegation uses this to handle events on a parent instead of individual children.

javascript

What is hoisting in JavaScript?

Easy

Hoisting moves declarations to the top of their scope during compilation. Variables and functions are hoisted differently.

javascript

Explain spread and rest operators

Easy

The spread operator ... expands iterables into individual elements. The rest operator collects multiple elements into an array.

javascript

What are JavaScript modules (import/export)?

Medium

ES6 modules allow splitting code into separate files with explicit imports and exports for better organization and reusability.

javascript

Explain destructuring in JavaScript

Easy

Destructuring extracts values from arrays or properties from objects into distinct variables using a concise syntax.

javascript

What is the difference between null and undefined?

Easy

undefined means a variable has been declared but not assigned a value. null is an intentional assignment representing "no value."

javascript

What are generators and iterators in JavaScript?

Hard

Generators are functions that can pause execution and resume later. Iterators are objects that define a sequence and return values one at a time.

javascript

What are WeakMap and WeakSet?

Hard

WeakMap and WeakSet hold "weak" references to objects, allowing them to be garbage collected when no other references exist.

javascript

What is the Proxy object in JavaScript?

Hard

Proxy wraps an object and intercepts operations like property access, assignment, and function calls, enabling custom behavior.

javascript

How do you handle errors in JavaScript?

Medium

JavaScript provides try-catch-finally for synchronous errors and Promise rejection for async errors. Custom error classes enable specific error handling.

javascript

What is debouncing and throttling?

Medium

Debouncing delays execution until after a pause in calls. Throttling limits execution to at most once per time period. Both optimize performance.

javascript

What are JavaScript design patterns?

Hard

Design patterns are reusable solutions to common programming problems. JavaScript commonly uses Module, Singleton, Factory, Observer, and other patterns.

javascript

Interview Tips for JavaScript