-1

Have a function assigned to a variable

var sq = function a(s){return s * s};

Now if i call sq(4) i am getting the result as 16 but if i try to call using the function name a(4) it throws an error "a is not defined"

Can we not call the function by its name once it is assigned to a variable.?

KrankyCode
  • 441
  • 1
  • 8
  • 24

1 Answers1

0

No, because you're using an assignment. You can just do var fn = function () { } or var fn = ()=> { } and get the same thing.

If you created the function and then assigned it to a variable, you could do both.

Basically,

function fn() {...}

var myFunc = fn;

You could then do both:

myFunc(); fn();

Yatrix
  • 13,361
  • 16
  • 48
  • 78