3 ms·
Not just the name, the entire function declaration is hoisted. That's the difference between: function () { ... var a = function () {}; }
by jbnicolai 13y ago
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.
- Zecc 13y agoAnd 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.