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 trialiliya caspi
5,718 Pointswhat is the difference between those two declarations within for loop
let token = new Token(i, this);
tokens.push(token);
or
tokens[i]=new Token(i, this);
1 Answer
Adam VanSlyke
15,988 PointsHi Iliya,
let token = new Token(i, this); tokens.push(token); The above code will create a new token object (line 1) and 'push' it onto the end of the existing 'tokens' array.
tokens[i]=new Token(i, this); This code will take the current value of 'i' and place the new token object in that index of the array.
For example if i = 3, it will place the new token object in the 4th place in the array.
Hope this helps.