Why the function's log is the function itself?

Viewed 58

I have encountered a problem that if the IFEE function's name is the same with variable's name in it. the output is the function itself. Why?

var b = 10;
(function b() {
  b = 20;
  console.log(b);
})();

1 Answers

Named function expressions create a read only variable in their own scope which matches their name and references themselves.

This is useful for writing recursive functions.

Related