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 Question Prototype

Could someone help me understand this line of code (from the video): return this.answer === choice;

Hi,

I'm a little confused with respect to this code: return this.answer === choice;

Does it first assign 'choice' to 'this.answer' and then return that? or does it first return 'this.answer' and then assign 'choice' to it? Or is it something altogether different? And in either case could anyone please explain why?

I'm sure this is something very basic, so apologies for asking, but I'm at an early stage of learning, and the video doesn't even have any explanation with respect to this line.

Thank you

1 Answer

return this.answer === choice;

That line return true or false value from comparison between this.answer and choice;

Let's say this.answer = 1 and choice = 1 then that line will return true. If choice = '1' then that line will return false because === operator also check the type of the variable. So string 1 is not identical with integer 1.

Got it. Thank you so much