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 React by Example Building the Application Filtering and Changing State Review

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

I don't understand why how logical expression evalutates

Question says:

"If the variable isFiltered is false, what would the following expression evaluate to? !isFiltered && 'showAll'"

I would have thought it was 'true', but it evaluates to 'showAll'. I don't understand why.

Abraham Juliot
Abraham Juliot
47,353 Points

There's a very informative video on short circuit evaluations at https://teamtreehouse.com/library/short-circuit-evaluation

I learned a lot from it. I do this so that others can read my code:

/*if*/ !isFiltered && /*then*/ 'showAll'

1 Answer

Nicholas Grenwalt
Nicholas Grenwalt
46,626 Points

Logical AND will only return true for the second expression if it literally evaluates to such as in doing a comparison (true && 12 > 5 for example), otherwise it will return whatever the actual value is. The string 'showAll' is true under the hood yes, but logical AND returns the value of that truthy expression, not the boolean representation of that value. The same goes for True && 'cat' would return the string cat. Hope that helps.