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.
Could someone help me understand this line of code (from the video): return this.answer === choice;
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.
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.