JavaScript Treehouse Club - MASH MASH - JavaScript Important Stuff - Part 3

What does the symbol || mean in Javascript?

I thought this symbol meant boolean false but I must be mistaken. Can anybody please enlighten me. I'm quite a noob to JavaScript :D

3 Answers

Sergey Podgornyy
Sergey Podgornyy
20,656 Points

It is logical OR operator.

You can find more info on link http://www.w3schools.com/js/js_comparisons.asp

Thanks Sergey..... That's really useful :D

jag
jag
18,265 Points

That's a logic operator, there are three types && || !

<script>
var x = 1;
var y = 2

// && is AND
// You need both conditions to be true for a true output
(x = = 1 && y == 2) //true

(true && true) //true
(true && false) //false
(false && true) //false
(false && false) // false

// || is OR
// Either condition needs to be true for a true output

(x == 1 || y == 3) // Condition 1 is true but condition 2 is false, the output is still true

(true && true) //true
(true && false) //true
(false && true) //true
(false && false) // false

// ! is NOT
// If the condition is false the output is true

!( x == 2 ) //true
!( true == true ) //false
!( true == false ) //true
!( false == false )// false


</script>