Leaderboard Archive
Javascript Apr 30, 2026

What gets logged?

function outer() {
  let count = 0
  return function inner() {
    count++
    return count
  }
}
const fn = outer()
console.log(fn())
console.log(fn())
A 1 and 1
B 1 and 2
C 0 and 1
D undefined and undefined
Explanation
This is a closure. The inner function "remembers" the count variable from outer, even after outer has finished running. Every time you call fn(), it increases the same count variable. This is how closures let you create private variables in JavaScript.
📝
Reviewed by CodeShot Editorial
Every challenge is code-reviewed by senior developers to ensure accuracy and real-world relevance. Learn more.

Ready for your shot?

Join thousands of developers solving one logic puzzle every morning.

Solve Today's Challenge →