+ 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