🟨 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)

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

javascript

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

javascript

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

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

javascript

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

javascript

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

javascript

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

javascript

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

javascript

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

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

javascript

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

javascript

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

javascript

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

javascript

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

javascript

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

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

javascript

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

javascript

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

javascript

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

javascript

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

javascript

Interview Tips for JavaScript