JSLint complains that the following (useless example) code is invalid:
(function (x) { "use strict"; if (x === 1) { return 1; } else if (x === 2) { return -1; } return 0; }(1));
Error: Problem with line character 4: Unexpected "else" after "return".
return 1;
Is this seriously suggesting that it is bad to use return statements inside an if / else structure?
He believes that this version is in order:
(function (x) { "use strict"; var returnval = 0; if (x === 1) { returnval = 1; } else if (x === 2) { returnval = -1; } return returnval; }(1));
javascript jslint
Hal Feb 28 '12 at 11:02 2012-02-28 11:02
source share