0

I was reviewing function declaration and function expression, separately, no problem

function add(a,b){return a+b};
var add2 = function(a,b){return a+b};
add(1,2)// 3
add2(1,2) // 3

But if I try to combine them the function declaration gets ignored

var add3 = function add4(a,b){return a+b}
add3(1,2) // 3
add4(1,2) // ReferenceError: add4 is not defined

I have no real case where I would need this type of declaration but I'm trying to understand why it wouldn't work

Anybody knows the right bit of literature ?

Jason Rogers
  • 18,658
  • 25
  • 74
  • 110
  • `var add3 = function add4(a,b){return a+b}` is just a function *expression*. In particular, it's a named function but it's not a function declaration. – VLAZ Nov 23 '19 at 18:30
  • 2
    When used as an expression the function name is only accessible inside the function itself , IIRC – Patrick Evans Nov 23 '19 at 18:30

0 Answers0