0

I am trying to understand how js parser works and wonder why there is no error in a declaration of var a below:

> var a = function b() {return 1;}
undefined
> typeof a
'function'
> typeof b
'undefined'
> function c() {return 1;}
undefined
> typeof c
'function'
> var d = function () {return 1;}
undefined
> typeof d
'function'

I think that:

  • named function MUST be declared as c(),
  • if you want to use function as var, you MUST declare it like d(use anonymous function)

I do not understand what is the difference between var a and var d declaration.

Can somebody tell me why function identifier is allowed in var declaration and what is the meaning of b in this case?

aeryaguzov
  • 1,103
  • 9
  • 20
  • @JamesAllardice If you closely look at the question, this is not the dupe of that. However, this has been asked many times. – Tushar Nov 24 '15 at 14:59
  • This was marked as a duplicate of another question, but that was asking about function expressions Vs function declarations, this is about named function expressions and anonymous function expressions. – Quentin Nov 24 '15 at 14:59
  • The question that I chose does provide an answer to everything asked here, in the 2nd most upvoted answer (but not the accepted answer). – James Allardice Nov 24 '15 at 15:06

0 Answers0