So, I'm using freecodecamp and it says that the following function is anonymous:
const myFunc = () => {
const myVar = "value";
return myVar;
}
console.log(myFunc.name);
Well, how come it's anonymous if its name is clearly "myFunc"?
So, I'm using freecodecamp and it says that the following function is anonymous:
const myFunc = () => {
const myVar = "value";
return myVar;
}
console.log(myFunc.name);
Well, how come it's anonymous if its name is clearly "myFunc"?
You are setting myFunc to reference an anonymous function. myFunc has a name, the anonymous function it references does not.
const myFunc = () => {
const myVar = "value";
return myVar;
}
// This returns myFunc name
console.log(myFunc.name);
// This returns anonymous function's name which is blank
console.log(
(() => {
const myVar = "value";
return myVar;
}).name
);