, , if :
if (isNaN(amt)) {
inputError = true;
} else {
if (amt === null || amt === 0) {
// If amt is blank or cancel button pressed then exit loop and exit function.
inputError = false;
return 0;
} else {
if (amt >= 10 && amt <=20) {
inputError = false;
} else {
inputError = true;
}
}
}
, JSLint, . , , - .
, , JSLint , , :
if (condition)
do_something();
- :
if (condition)
do_something();
do_something_else();
. , , , .
, , return, .
, if ( ), , else. if (, return), else ( else) ( else if)
stmt('if', function () {
var paren = next_token;
one_space();
advance('(');
step_in('control');
no_space();
edge();
this.arity = 'statement';
this.first = expected_condition(expected_relation(expression(0)));
no_space();
step_out(')', paren);
one_space();
this.block = block('if');
if (next_token.id === 'else') {
if (this.block.disrupt) {
next_token.warn(this.elif ? 'use_nested_if' : 'unnecessary_else');
}
one_space();
advance('else');
one_space();
if (next_token.id === 'if') {
next_token.elif = true;
this.else = statement(true);
} else {
this.else = block('else');
}
if (this.else.disrupt && this.block.disrupt) {
this.disrupt = true;
}
}
return this;
});
unnecessary_else , , :
if (condition) {
return 0;
} else {
do_something();
}
:
if (condition) {
return 0;
}
do_something();
use_nested_if , , , , return. , , .
, , , , , , . , tolerate_non_nested_if . , , .
, - if, else, ( if/else, ).
, , , :
if (isNaN(amt)) {
inputError = true;
} else {
if (amt === null || amt === 0) {
// If amt is blank or cancel button pressed then exit loop and exit function.
inputError = false;
return 0;
} // no else needed here.
if (amt >= 10 && amt <=20) {
inputError = false;
} else {
inputError = true;
}
}