JS: Function.prototype.name

By Xah Lee. Date: . Last updated: .
f.name

Value is the name of the function, or empty string.

// arrow function assigned to a var, has a name of the var
const f1 = () => {};
console.log(f1.name === "f1");

// is own property
console.log(Object.hasOwn(f1, "name"));

// anon arrow function has name of empty string
console.log((() => {}).name === "");
// function declaration
function fd() {}
console.log(fd.name === "fd");

// function expression assigned to a var
const fe = function () {}
console.log(fe.name === "fe");

// anon function expression has name of empty string
console.log((function () {}).name === "");