ตัวดำเนินการ OR ตรรกะใน JavaScript

ตัวดำเนินการ || แทน ตรรกะ OR และต้องการให้เงื่อนไข อย่างน้อยหนึ่งเงื่อนไขเป็นจริง

ในตัวอย่างต่อไปนี้ ถ้าตัวแปร num1 มากกว่า 0 หรือตัวแปร num2 มากกว่า 0 เงื่อนไขจะเป็นจริง (เพียงพอที่เงื่อนไขอย่างน้อยหนึ่งเงื่อนไขจะเป็นจริง):

javascriptlet num1 = 10;
let num2 = -5;

if (num1 > 0 || num2 > 0) {
  console.log('+++'); // จะทำงานที่นี้
} else {
  console.log('---');
}
Задание 1

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num1 = -10;
let num2 = -10;

if (num1 >= 0 || num2 >= 0) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 2

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num1 = 0;
let num2 = 0;

if (num1 >= 0 || num2 >= 0) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 3

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num1 = 0;
let num2 = 5;

if (num1 >= 0 || num2 >= 0) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 4

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num1 = 5;
let num2 = 5;

if (num1 >= 0 || num2 >= 0) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 5

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num1 = -5;
let num2 = 15;

if (num1 >= 0 || num2 >= 0) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 6

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num = 1;

if (num == 0 || num == 1) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 7

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num = 2;

if (num == 0 || num == 1) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 8

โดยไม่ต้องรันโค้ด จงพิจารณาว่าอะไรจะถูกแสดงออกมา ที่คอนโซล:

javascriptlet num = 2;

if (num == 0 || num == 1 || num == 2) {
  console.log('+++');
} else {
  console.log('---');
}