+ 4

How do you add in a different order other than i++ ?

Iā€™m a Rookie to JavaScript and Iā€™m really interested to know how do u add number in, 2ā€™s and 3ā€™s and 4ā€™s or any other synonymous way other than i++! I hope someone will come with a great example along with explanation ! Thanks in advance šŸ˜

27th Feb 2018, 9:29 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
4 Answers
+ 17
i++ is the same as i+=1 and i=i+1 There is no other way to add 2 to i except i+=2 or i=i+2
27th Feb 2018, 9:32 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 5
Thanks a lot @Swapnil! I thought it would be more complicated but never realised it would be this easy šŸ˜…šŸ™ŒšŸ»šŸ™
27th Feb 2018, 9:34 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
+ 4
Yea Iā€™m getting a catch on to it now! Thanks man @ashish kumar
27th Feb 2018, 9:42 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
+ 2
++i and i++ are same when initialsed to a variable. Any of both can be used, only difference being in '++i' the value is incremented first and then used while in 'i++' the value of i is used and then decremented. As said by Swapnil i=i+1 and i+=1 are equal and can be used anywhere possible.
27th Feb 2018, 9:38 AM
Ashish Kumar
Ashish Kumar - avatar