Logical OR Operator in JavaScript

Level 270 keystrokes

Uses the || operator to check if at least one condition is true.

JavaScript code

// Declare a variable with the boolean value true
1let x = true;
// Declare a variable with the boolean value false
2let y = false;
// || (OR) returns true if AT LEAST ONE value is true
// true || false = true (one is true)
3console.log(x || y);
// false || false = false (neither is true)
4console.log(y || y);

Output

true
false
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • ;× 4
  • |× 4
  • .× 2
  • (× 2
  • )× 2
  • =× 2

More JavaScript examples at level 2

← JavaScript typing practice