I’ve seen code like the following in some JS libraries:
var i;
for (i = 20; i >= 0; i -= 1)
{
}
I wonder why they would choose to decrement i in this fashion. Is there something problematic about using ++ and -- in javascript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Douglas Crockford, aka the godfather of JavaScript, discourages the
++.Personally, the — or ++ is completely okay in a for loop as its meaning is very clear. I tend to follow most of Crockford’s guidelines though because its generally the basis of JS conventions.
See more here.