🔰as variable
🚧 施工中
JS ⟩ concepts ⟩ expression ⟩ function expression ⟩ as variable
// ⭐️ the variable to which the "function expression" is assigned:
// -----------------------------------------------------------------------------
// • will have a `name` property
// • the name won't change if it's assigned to a different variable.
// • (implicit name) if function is anonymous, it will be the "variable name".
// • (explicit name) if function is named, it will be the "function name".
// ⭐️ (anonymous) function expression
// ╭──── ⭐️ ────╮
const f = function() { };
f.name // "f" (implicit name = variable name)
const f2 = f;
f2.name; // "f" (the `name` won't change❗)
// ⭐️ arrow function
// ╭─ ⭐️ ─╮
const h = () => {};
h.name; // "h" (implicit name also applies to arrow functions)
// ⭐️ (named) function expression
// ╭────── ⭐️ ───────╮
const g = function game() { };
g.name; // "game" (explicit name = function name)
typeof g; // 'function'
typeof game; // undefined (`game` is only scoped within the function body❗)Last updated
Was this helpful?