true or false = true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

true or false = true?

QUESTION var x = false || true; document.write(! (x !== true)); why false || true equal to true? Hope you can solve this for me! Thanks a lot!

20th Nov 2018, 4:51 PM
Rex Hung
4 Answers
+ 3
true and false is a boolean. For example : console.log(2 == 3) : false because the 2 numbers is different. console.log(2 == 2) : true because the 2 numbers is the same.
20th Nov 2018, 5:20 PM
program
program - avatar
+ 1
The || operator means ‘or’, so a || b is ‘a or b’ and is true if either a is true or b is true. With false || true, the right hand side is clearly true, so the or statement evaluates as true.
20th Nov 2018, 5:17 PM
Russ
Russ - avatar
+ 1
Logical "OR" ( || ) operator return true if one ore more of the expressions to be evaluated is true. You can read more about logical operators here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators.
20th Nov 2018, 5:20 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Thanks
21st Nov 2018, 2:42 PM
Rex Hung