I’m studying the ECMAScript spec to find out what the expected behavior of vars
statements inside a block is according to the spec:
function test() {
console.log('before block', bar);
{
console.log('in block before declaration', bar);
var bar = 30;
console.log('in block after declaration', bar);
}
console.log('after block', bar);
}
test();
The DeclarationInstantiation
semantics indicate that variables declared with var
are collected by VarDeclaredNames
and VarScopedDeclarations
semantics. But the spec only defined the semantics for empty block without any statement:
How could I know what the VarDeclaredNames
and VarScopedDeclarations
of Block { statementList }
should be?
I found other semantics include Block { statementList }
, so I expect the VarDeclaredNames
and VarScopedDeclarations
may consist of it too, or how should the implementations treat block without instructions?