JavaScript – Why is this function declaration created in a function expression “undefined”?

It isn’t a function declaration. It is a function expression that happens to have a name. The name does not create a variable, but you can see it on the object

quentin@raston ~ $ node
> var p;
undefined
> p = function a() { return 'Hello' }
[Function: a]
> typeof p; // returns 'function'
'function'
> typeof a; // returns 'undefined'
'undefined'
> p
[Function: a]
> p.name
'a'
>

Leave a Comment