JSHint is warning you of a potential bug. It is expected that the 2nd part of a for
statement will be a Boolean expression. Normally, you'd use one of the comparison operators for this (==
, ===
, !=
, >
etc..). Since the expression is e = formErrors[i]
it looks like it might be a mistake, possibly due to a missing equal sign. This is a common typo that causes a lot of bugs.
Apparently, in this case it is not a bug, but rather an intentional usage of the fact that any expression evaluates to something, and an assignment expression evaluates to the assigned value:
So the for
statement actually assigns a new value to e
, but also evaluates that value as a condition, casting it to Boolean if required.
You could refactor your code such that it both assigns the value and uses a casting operation that would satisfy JSHint and make the code a bit more obvious to the reader:
for (var e, i = 0; !!(e = formErrors[i]); i += 1)
The 2nd !
(the one directly in front of (e...
) causes a casting to Boolean, but also negates it, the 1st !
reverts this negation.