๐ฐfunction name scope
JSโฉ scope โฉ function name scope
the name identifier of a function expression is in its own function name scope, nested between the outer enclosing scope and the inner function scope.
replit๏ผfunction expression identifier
var outerName = function innerName() {
// โญ shadowing `innerName` is allowed inside function body
// -----------------------------------------------------------------------
// if `innerName` was in the function's scope, we'd expect an error here:
// namely, SyntaxError: Identifier 'innerName' has already been declared
let innerName = 1234;
return innerName;
};
outerName(), // 1234
๐ โ๏ธ SyntaxError โฉ identifier 'xxx' has already been declaredโ๏ธ
Last updated
Was this helpful?