Hacker News new | ask | show | jobs
by nayuki 349 days ago
> Somewhat confusingly, we can also give our function expression a name. One that’s separate from the variable name [...] This throws an error. If we can’t use that name, then what’s the point of it? Well, takeyWhiley will show up if we throw an error in our code.

There is another reason: If you give a name to a function expression, the function can directly recurse on itself without the use of combinators. For example:

  const factorial = function fact(n) {
      if (n == 0)
          return 1;
      else
          return n * fact(n - 1);
  };