🔰function name scope

JSscope ⟩ 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.

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

👉 ⛔️ SyntaxErroridentifier 'xxx' has already been declared❗️

Last updated