I just lost quite a bit of time because I changed a JavaScript function that read (something like)
function F(a,b,c) {
return x(a,b,c) +
y(a,b,c) +
z(a,b,c);
}
to
function F(a,b,c) {
return // x(a,b,c) +
y(a,b,c) +
z(a,b,c);
}
when I needed to test something.
The changed function returns undefined, of course, because the language does not require a semicolon and assumes the return to be a complete statement.
Unfortunatly, when I commented out x(a,b,c) I didn’t think of this implication. So, is there a way to prevent such stupid misstakes in the future.
Integrate JSLint into your build, and fail builds when you detect
Problem at line 7 character 12: Unreachable 'y' after 'return'.Make this generic for line and character, of course. What you’re really looking for is “Unreachable after return”.