Question 09 / 14
How can a function binding become a number?
Topic: Function calls
The function declaration initializes a, then the var initializer overwrites that same binding with 2.
Solve it with the execution visualizerStep through every binding, function call, and console output below.Predict the output
At the typeof expression, is a still the declared function?
var a = 2
function a() {
console.log(3)
}
console.log(typeof a)Reveal the answer and explanation
Expected output
numberWhy this happens
Declaration instantiation initializes a with the function object before statement evaluation begins.
The var declaration does not create another a binding, but its initializer is still an assignment that runs in source order.
After var a = 2 executes, a contains a number, so typeof a evaluates to "number".
What this question tests
- shared binding name
- function initialization
- runtime assignment order
Runtime assumptions
This question concerns classic function and var declarations in one scope.