Ctrl K
Frontend · Junior · Theory

What is a closure in JavaScript? Give an example of where it's used in practice.

~4 min by voice

How to approach it

The interviewer wants to see whether you understand how lexical scope works: a function remembers the environment where it was created and uses it after the outer function has finished. Plus whether you can show why this matters in real code, not just give a definition.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsWrite a debounce function. It takes another function and a delay in milliseconds and returns a new function that calls the original only once that delay has passed since the last call. JuniorExplain how prototypal inheritance works in JavaScript, and what actually happens when you write a class with extends. Mid-levelExplain how the event loop works in JavaScript. And what gets printed to the console if a script has, one after another, a console.log, a setTimeout with zero delay, and a Promise.resolve().then? JuniorWhat is a decorator in Python? How would you write your own decorator, for example one that measures how long a function takes to run? JuniorWhat is a promise, and how does async/await differ from a then chain? Junior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min