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 trial

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

2 Answers

Steven Parker
Steven Parker
231,275 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,009 Points

means or

if (true or true)

{

doSomething()

}