Back to questions
JuniorTheoryCommon
What does the program print?
function show() {
console.log(x);
var x = 5;
}
show();undefined
- Expecting
ReferenceError, as withlet: avarexists in the whole function from its first line, holdingundefineduntilvar x = 5runs. - Expecting
5, as if the whole line moved up: only the variable exists early, and the value5is assigned when its own line runs.
- What does the program do if
var x = 5is replaced withlet x = 5? - Can a function declared with
functionbe called on a line above its declaration?