Logical OR in JavaScript
The ||
operator is a logical OR and
requires at least one condition to be met.
In the following example, if the variable
num1
is greater than 0
or the
variable num2
is greater than 0
,
then the condition will be true (it is enough
at least one of the conditions to be met):
let num1 = 10;
let num2 = -5;
if (num1 > 0 || num2 > 0) {
console.log('+++'); // it will work
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num1 = -10;
let num2 = -10;
if (num1 >= 0 || num2 >= 0) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num1 = 0;
let num2 = 0;
if (num1 >= 0 || num2 >= 0) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num1 = 0;
let num2 = 5;
if (num1 >= 0 || num2 >= 0) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num1 = 5;
let num2 = 5;
if (num1 >= 0 || num2 >= 0) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num1 = -5;
let num2 = 15;
if (num1 >= 0 || num2 >= 0) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num = 1;
if (num == 0 || num == 1) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num = 2;
if (num == 0 || num == 1) {
console.log('+++');
} else {
console.log('---');
}
Without running the code, determine what will be output to the console:
let num = 2;
if (num == 0 || num == 1 || num == 2) {
console.log('+++');
} else {
console.log('---');
}