Public Deck

JavaScript Interview Prep - 50 Questions

Ace your JavaScript interviews with 50 essential questions covering closures, promises, prototypes, and modern ES6+ features.

AnyFlashcards50 cards

Preview

Front

What is a closure in JavaScript?

Back

A function bundled with its lexical environment. Allows an inner function to access variables from an outer scope even after the outer function has returned.

Front

What is lexical scoping?

Back

Variable access determined by the physical location in source code. Functions are executed using the scope chain that was in effect when they were defined.

Front

How do closures enable private variables?

Back

By returning an object with methods that access local variables. Example: function counter() { let count = 0; return () => ++count; }

Front

Why does using 'var' in a loop often cause closure issues?

Back

'var' is function-scoped, not block-scoped. All iterations share the same variable instance; use 'let' to create a new binding for every loop iteration.

Front

Can closures cause memory leaks?

Back

Yes, if they hold onto large objects unnecessarily. The garbage collector cannot free memory for variables still referenced by an active closure.

Front

What is function currying?

Back

Transforming a function with multiple arguments into a sequence of nesting functions. Example: const add = a => b => a + b; add(1)(2); // 3

Front

How is memoization implemented using closures?

Back

By storing a cache object within the outer function's scope. The inner function checks the cache before performing expensive computations.

Front

What is the scope chain in a closure?

Back

The hierarchy of Local, Outer, and Global scopes. JavaScript searches for variables starting from the innermost scope outward.

Front

What is a Promise in JavaScript?

Back

An object representing the eventual completion or failure of an asynchronous operation. It acts as a placeholder for a value that is not yet known.

Front

What are the three states of a Promise?

Back

Pending, Fulfilled, and Rejected. A promise starts as pending and settles into either fulfilled (success) or rejected (error).

+ 40 more cards

Related Flashcard Decks

Ready to study?

Sign up for free to copy this deck and start learning with spaced repetition.

Get started for free