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 trialUnsubscribed User
3,567 PointsI' m missing something....
why are we using student.name on the function getStudentReport before we assigned students[i] to it...
I mean, is on the for loop where we assigned to the empty var student, the value of students[i]...
3 Answers
Alex Boyers
15,168 PointsIn the for
loop, the student
variable is given the value of students[i]
before the getStudentReport
function gets called, so the value will be updated when it runs.
It is a little confusing when reading the code from top to bottom. Just remember that variables may change values before the function gets called in the code.
Ryan Field
Courses Plus Student 21,242 PointsIn this case, student
is being used as both a shorthand way of writing students[i]
, and to make it more understandable (i.e., we are referring to one particular student out of an array of students).
Unsubscribed User
3,567 Pointsyep and thanks, but what I still don't get is, the array's name is students, student is an undefined variable (var student;) so, if I say student.name for JS it should meant nothing... My main problem is that we assigned the value of students[i] to the variable student way after in the for loop... It's kinda confusing...