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 trialLeanne Millar
5,334 PointsWhat 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
20,660 PointsIt is logical OR operator.
You can find more info on link http://www.w3schools.com/js/js_comparisons.asp
Leanne Millar
5,334 PointsThanks Sergey..... That's really useful :D
Sergey Podgornyy
20,660 PointsYou are welcome ;)
jag
18,266 PointsThat'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>