There are three logical operators in JavaScript:

  1. || (OR),
  2. && (AND),
  3. ! (NOT).

The “OR” operator is represented with two vertical line symbols:

result = a || b;

In classical programming, the logical OR is meant to manipulate boolean values only. If any of its arguments are true, it returns true, otherwise it returns false.

In JavaScript, the operator is a little bit trickier and more powerful. There are four possible logical combinations:

console.log( true || true );   // true

console.log( false || true );  // true

console.log( true || false );  // true

console.log( false || false ); // false

The result is always true except for the case when both operands are false.If an operand is not a boolean, it’s converted to a boolean for the evaluation.

if (1 || 0) { // works just like if( true || false )
  console.log( 'truthy!' );

The number 1 is treated as true, the number 0 as false.