Why is jslint complainig about this syntax:
var myint;
myint = 0;
myint++;
www.jslint.com response:
Unexpected '++'. myint++;
Why is jslint complainig about this syntax:
var myint;
myint = 0;
myint++;
www.jslint.com response:
Unexpected '++'. myint++;
JSLint doesn't like ++
, it wants you to use myint += 1
. This is highly debatable, see Why avoid increment ("++") and decrement ("--") operators in JavaScript?
There is an option to let it pass, though (on the web interface, it's under "tolerate...").
From JSLint help:
The
++
(increment) and--
(decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces. Also, preincrement/postincrement confusion can produce off-by-one errors that are extremely difficult to diagnose. There is aplusplus
option that allows the use of these operators.
Crockford's argument against ++
and --
is that they are "too tight, too tricky, too cryptic" (page 112 of Javascript: the good parts). Your mileage may vary. Use them if you want, or if you think they are too confusing and hamper readability, don't.
You can switch that rule off in JSLint if you don't buy Crockford's argument.