Passing this code through jsHint:
var A = function (spec) { "use strict"; var a = function () { return b(); }; var b = function () { return 5; }; a(); };
returns this error:
Line 4: return b(); 'b' is not defined.
I understand that this may be related to "lifting" as described here: Order of JavaScript functions: why is this important?
However, the following code returns the same error:
var A = function (spec) { "use strict"; function a () { return b(); } function b () { return 5; } a(); };
If I understand correctly, at least the second piece of code should not return an error. Am I mistaken?
Even given the lifting mechanism, I still don't understand why the first piece of code should be wrong. Function a is called only after function b defined, so b will be closed by a . Is my code incorrect or jsHint incorrect?
I understand that this question is purely academic in nature, because the code works as expected in all browsers. However, I would like to know why jsHint throws an error.
source share