I have this code:
if ( something is true ) {
var someVar = true;
} else {
var someVar = false;
}
JsHint is saying that
You shouldn't put var
declarations in such places. Put the var
declaration before the if
, and then just set "someVar" to a value.
Indeed, here you don't need an if
statement at all:
var someVar = !!(something);
will do the same thing. (The double application of !
ensures that "someVar" is set to either true
or false
, based on the "truthiness" of something
.)