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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Alec Sandoval
Alec Sandoval
1,687 Points

or operator

I flipped flopped a certain line of code involving the "or":

if (search.toLowerCase() === 'quit' || search === null)

and got the error "student_report.js:20 Uncaught TypeError: Cannot read property 'toLowerCase' of null". Why is that line of code not the same as:

if (search === null || search.toLowerCase === 'quit')

2 Answers

Vladut Astalos
Vladut Astalos
11,246 Points

Yes they mean the same thing but if the first condition is true, that means 'search' is null, then the second condition can not be verified because you can't apply toLowerCase() method on a null object.

Vladut Astalos
Vladut Astalos
11,246 Points

I'm not sure but I think that happens because in your first example if the first condition is true then the second doesn't make sense anymore. I mean if search.toLowerCase() === 'quit', then is clearly that search isn't null, there is no need to check that. And in your second example if the first condition is true and search is indeed null than you can not convert it to lower case because there is nothing to convert.

Alec Sandoval
Alec Sandoval
1,687 Points

Don't the two conditions mean the same thing? If (search === 'quit' OR search === null) vs if (search ===null OR search === 'quit')