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 Object-Oriented JavaScript (2015) Practice Project Quiz Prototype

Timothy Mattingly
Timothy Mattingly
15,935 Points

Defining instances in an array

How does creating instances in an array without assigning them a variable work? He's assigning them when he defines the array? That' isn't making any sense. Is there any sources out there on this? I've been searching and can't find anything even close. I don't understand why no one would cover adding instances to arrays. Thank you.

1 Answer

Steven Parker
Steven Parker
231,269 Points

These instances ARE being assigned to a variable. They are being assigned to the array variable questions.

The code in the video is essentially the same as this:

var questions = [];
questions[0] = new Question(blabla...);
questions[1] = new Question(blabla...);

The video method just defines and assigns the array at the same time. It's just a short cut.

Timothy Mattingly
Timothy Mattingly
15,935 Points

Ah, if only the teacher had said that. Oh well, thanks for the response Steven. The code example was really helpful.