JavaScript Closures Quiz
A closure is a function that remembers the variables from the scope where it was created, even after that scope has finished running. Closures power private state, callbacks and many common patterns.
They’re also one of the most asked topics in JavaScript interviews.
Closures questions
- How does a closure counter work in JavaScript?
- Why does var in a loop with setTimeout print 3 3 3?
- Why does let in a for loop fix the setTimeout closure problem?
- Do two closures from the same function share state?
- Does a JavaScript closure capture the value or the variable?
- How do closures create private variables in JavaScript?
- How do you write a once() function with a closure?