For this code:
var i = 0;
for (i < menuitem.length; i += 1;)
JSlint returns:
Expected a conditional expression and instead saw an assignment.
Expected an identifier and instead saw ‘)’.
And refuses to continues scanning.
This code works fine but what is wrong? How could I write this with an “if” statement? (if that is what jslint means).
Thanks for your help guys!
Yeah, JSLint is pretty vicious. As others have pointed out, you’re not filling things in in the right places, but aside from that, JSLint requires that you put something in the initialization part of the
forloop. There are a couple options you can do to make it play nice without messing with your logic, though. My favorite is to just reseti(even though it’s already set):This make JSLint happy and also ensures that
igets reset if you decide to use it for anotherforloop in the same lexical scope. Another option is to just toss anullin there to fill the space (if you don’t want to reset the value ofi):Both work fine and appease the ever-so-worrisome JSLint. However, no one will really care if you just leave the initialization part blank (aside from JSLint). You might try JSHint, as it’s a bit more forgiving on this sort of thing.