๐Ÿ”ฐnamed function expression

๐Ÿšง ๆ–ฝๅทฅไธญ

JS โŸฉ value โŸฉ function โŸฉ expression โŸฉ named

a function expression with an internal name.

  • outerName is in the outer scope

  • innerName is in the inner "implied scope".

// โญ named function expression
// ------------------------------------
//                       โ•ญโ”€โ”€nameโ”€โ”€โ•ฎ
var outerName = function innerName() {
    console.log(innerName);
    //          ^^^^^^^^^ <---- โญ visible from inside
};

outerName();      // [Function: innerName]

outerName.name,   // "innerName"
innerName,        // โ›” ReferenceError: `innerName` is not defined
                  //    (โญ `innerName` invisible from outside)

Last updated