๐Ÿ”ฐfunction name scope

JSโŸฉ scope โŸฉ function name 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

๐Ÿ‘‰ โ›”๏ธ SyntaxError โŸฉ identifier 'xxx' has already been declaredโ—๏ธ

Last updated

Was this helpful?