Why can’t I set a JavaScript function’s name property?

Because name is a non-standard, non-writable property of function objects. Function declarations and named function expressions are named, while you have an anonymous function expression whose name is "".

You probably wanted a plain object:

var person = {
    name: "John Smith",
    age: 21,
    profession: "Web Developer"
};

Leave a Comment