Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Combining Strings

Rich Braymiller
Rich Braymiller
7,119 Points

I just can't wrap my head around it

I am having a hard time wrapping my head around the += Struggling to understand the shorthand...sorry, I'm new to javascript...

3 Answers

so you have :

i = i + 1;

instead of writing it like that you juste take off the "i" after the equal sign, and you put the addition sign before the equal sign :

i += 1;

it means that you are adding 1 to the last value of "i".

Lets say you have

var x = 10

Then you do this:

x+= 5

This is saying take x which is 10 , and add 5 to it.

So, x+=5 will give you 15.

you welcome :)