Hacker News new | past | comments | ask | show | jobs | submit login

Not just the name, the entire function declaration is hoisted. That's the difference between:

    function () {
      ...
      var a = function () {};
    }
which gets hoisted to:

    function () {
      var a;
      ...
      a = function () {};
    }
and:

    function () {
      ...
      function a () { };
    }
Which gets hoisted in it's entirety to:

    function () {
      function a () { };
      ...
    }
Which will cause difference behaviour between the two when calling a in the ... section, working in the latter case but undefined in the first.

I don't think the grandparent was unclear about this in his post though.




And as a bonus, the latter gets its name set. Of course you could also name it in the function expression, but then you'd just be repeating yourself.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: