0
function a(){}
a.name = 'foo';
console.log(a.name); // a

I declared a function "a", adding a field and assigning the value 'foo', browser console printed 'a' instead of 'foo', why?

hikari
  • 17
  • 3
  • 7
    a functions "name" is not writable - in other words ... `name` is a standard (read-only) property of a function - if you did `a.Name='foo'` then you'd be golden – Jaromanda X Jul 02 '21 at 08:37
  • 2
    You’re not really _adding_ a field. Functions have a read-only `name` property which refers to the explicit or inferred name of the function from its definition. – Sebastian Simon Jul 02 '21 at 08:39

0 Answers0