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 ff = () => {};
console.assert(ff.name === "ff");

// is own property
console.assert(Object.hasOwn(ff, "name"));

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

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

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