CodePeek
Practice / ScopeBack to CodePeek

JavaScript var hoisting: Before its time

Puzzle 11 of 15 · var hoisting

Read a function that logs a var binding before and after its assignment. Predict both lines while considering declaration timing. Choose an output below, then check the explanation. No signup needed. Browse puzzles by topic →

Scope / var hoistingJavaScript
function peek() {
  console.log(value);
  var value = 7;
  console.log(value);
}
peek();

Predict the console output. Each line is a separate log.

What’s the output?

Choose the output

Starter puzzles 15