473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Incrementing Vars Preferred Method?

RMWChaos
137 100+
Yet another inane question...but I am looking for coding "best practices" here.

I have always used i++ to increment vars, but have recently found that some well-respected JS coders such as Douglas Crawford use a different method i += 1.

When incrementing by a single integer (1), is the += method still preferred? I can see if you wanted to increment by a value greater than 1 (i.e. i += 2, 3, ... infinity), but otherwise, what is the benefit? Are there situations where i++ can fail or cause problems?

Thanks.
Dec 23 '07 #1
2 1046
mrhoo
428 256MB
Expand|Select|Wrap|Line Numbers
  1.  
  2. (function(){
  3.     var i= 0,j= 0, tem;
  4.     var A= [],B= [];
  5.     while(i<10){
  6.         A[i]= i+= 1;
  7.         B[j]= j++;
  8.     }
  9.     alert('i+=1 returns: '+A+'\ni++ returns: '+ B);
  10. })()
  11.  
Dec 23 '07 #2
RMWChaos
137 100+
Oh, brilliant!

Thanks!
Dec 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kenny Ashton | last post by:
Hello gurus Can I ask you opions on the best compromise for storing Access Ado connection strings in a IIS4 standard ASP environment. For any method I use, there seems to be an article somewhere...
22
by: Jane Withnolastname | last post by:
I have been using the charset windows-1252 for a while, but it was pointed out to someone else in this group recently that it's a Microsoft creation (I'm sure I'm getting my facts wrong or skewed)...
6
by: JDP | last post by:
First off let me say that http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/converttoaspnet.asp would not work as I see it. Right off, I can't have a cookie. ...
4
by: Sylvain Girard | last post by:
Here's the situation: I need to redirect to another page and post some vars. Response.Redirect doesn't work with post vars (at least not that I know of) and a WebRequest doesn't open the new page...
2
by: r.roest | last post by:
Hi, I'm looking for a way to fill static vars from a different c-file. Here is what I want to do: file1.c static DEBUG calling function X using DEBUG to display information calling...
10
by: John A Grandy | last post by:
Say I have Class1 which contains static Class2 var1 = new Class2(); Is Class2 constructor code only executed if var1 is referenced in the code-execution path ? Or is Class2 constructor code...
19
RMWChaos
by: RMWChaos | last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to...
1
by: Ken Fine | last post by:
I am wondering if there is a build-in method in .NET for arbitrarily and correctly combining/concatenating querystring variables into a valid querystring. i.e. I might have the following vars I...
1
by: BrendanC | last post by:
I'm trying to understand reflection/introspection in Python. How can I identify the the type of attribute (e.g. instance var) in a class? The following returns all the class attributes (methods and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.