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 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')