Here's what your code looks like when compiling:
function f() { return "global"; }
function test(x) {
var result = [];
var f;
if (x) {
f = function () { return "local"; }
result.push(f());
}
result.push(f());
return result;
}
A variable f(a variable containing a pointer to a function) is declared at the top of the function, but is defined in a conditional expression.
JavaScript , . , , , . f.
:
function f() { return "global"; }
function test(x) {
"use strict"
var result = [];
if (x) {
function f() { return "local"; }
result.push(f());
}
result.push(f());
return result;
}
test(true);
test(false);
:
["local","global"] //test(true);
["global"] //test(false);
, f , .