Skip to content
Advertisement

Are booleans implicitly true?

I’m a bit confused on this bit of code.

My professor explained that the output will always be true but I’m confused on why.

I changed the boolean to both true and false but the output is always true and I’m having a hard time explaining the logic behind it. I assumed that since a false && true will always represent true, then the true and false cancels out like algebra? Apologies if I’m confusing you guys, I’m quite confused myself!

JavaScript

Advertisement

Answer

This code for calculating output means:

JavaScript

Therefore, when answer is true:

JavaScript

And when answer is false:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement