Welcome to the Treehouse Community
Looking to learn something new?
jason chan31,008 Points
Why didn't he teach ++ seems like easier notation and you don't have to type three characters?
rigoberto contreras9,035 Points
++ increases the integer by one and += increases the integer by the number of your choice.
You should avoid using ++ (and --). Not only does += (or -=, *=, etc) give you more power over your interval, it will also eliminate confusing errors that may come up down the road from using a ++/-- operator, especially since you can put
++var and in some cases they will work the same and in others, they won't.
var counter = 0; var myArray = ; //You would think that this would increase the counter variable and then //assign the value "foo" to that index //But instead it uses the present value of counter as the index and then increases counter myArray[counter++] = "foo"; console.log(myArray); //Returns foo at index 0 console.log(counter); //Returns 1
And then this case:
var counter = 0; var myArray = ; //Using ++counter will instead increase counter first and then //use the value it just got as the index //in this case 1 myArray[++counter] = "foo"; console.log(myArray); //Returns foo at index 1, 0 is undefined console.log(counter); //Returns 1