Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React by Example Building the Application Connecting the Confirm Guests Handler

Could some one explain for me why ?

Why Gail use this statement if(index === indexToChange)? So if index value is the same value of indexTochange then what is the logic to compare two things are the same?

1 Answer

Calin Bogdan
Calin Bogdan
14,920 Points


Guil is actually iterating through all indexes and is changing only the selected index, indexToChange. That's why he's comparing the two, they're not identical.

Let's say he wanted to change the item at index 5. He's iterating through all items' indexes and checks whether the iterated index equals 5. If it doesn't, he will keep looking for the next item. On the other hand, if the index equals 5, he will perform the operation.

Hope it helped!