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

2 Answers

Steven Parker
Steven Parker
200,778 Points

It means "or". For example: if (a < 3 || a > 9) means "if a is less than 3 or a is greater than 9". In this sense, it is known as a "logical operator", and works similarly to what it does in several other languages..

But JavaScript is a bit different from other languages, in that is has the concept of "truthiness". So it doesn't have to be used only with expressions that are either "true" or "false". If the expression on the left is determined to by "truthy", it will return that, otherwise it will return the one on the right. So, it can also be used like this:

a = "yes";
console.log(a || "nothing");  // this will print out "yes".
a = "";
console.log(a || "nothing");  // this will print out "nothing".

I guess that was a bit more information than you needed just for the quiz. :smile:

jason chan
jason chan
31,001 Points

means or

if (true or true)