Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why shouldn't we use ++ in javascript? [duplicate]

Tags:

javascript

Possible Duplicate:
Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?

I've heard in a few places that it is not recommended to use ++ & -- in javascript, and we should be using += 1 or -= 1 instead. Can anyone clarify why for me?

like image 440
Bala Clark Avatar asked Jul 13 '10 15:07

Bala Clark


3 Answers

The only reason I can think of, is that your Javascript is more likely to be edited by a moron than any other code you write (html??).

So to a noob,

x=x+1 ;

is more readable than

x++;

When dealing with experienced programmers, it really doesn't matter.

like image 167
Chris Cudmore Avatar answered Oct 05 '22 23:10

Chris Cudmore


Because Douglas Crockford has his own opinions of how confusing something may or may not be. They are fine to use, JSLint is just projecting his opinions.

like image 37
tbranyen Avatar answered Oct 06 '22 01:10

tbranyen


Anyone mind if I make the opposite suggestion...?

Please use the increment (++) and decrement (--) operators when you can. Much more straightforward. (And that's what they're there for.)

like image 32
froadie Avatar answered Oct 06 '22 00:10

froadie