?
8>5?true:false;
Copy the code
Conditions? Value 1: value 2 means 8 is greater than 5? Greater is true and greater is false, right? If the condition in front of number is true, the first value is executed; if not, the second value is executed.
&&
- The result is true only if both conditions are true;
- If one of them is false, the result is false;
- When the first condition is false, the next condition is not judged
let a = 1,
b = 2
let result = a && b
console.log(result) / / 2
Copy the code
Note: If the result is true, the second true value will be returned; If the result is false, the first false value is returned
||
If either condition is true, the result is true. If both conditions are false, the result is false. When a condition is true, subsequent conditions are not judged
let a,
b=2
let result = a || b
console.log(result) / / 2
Copy the code
Note: when a value is involved in a logic or operation, the result is true, and the first true value is returned; If the result is false, the second false value is returned;
!
When the condition is false, the result is true; And vice versa.
Expression a && expression b:
- Evaluate the result of expression A (or function),
- If True, the expression b (or function) is executed and the result of b is returned
- If False, return the result of a;
Expression a | | b:
- Evaluate the result of expression A (or function),
- If Fasle, the expression b (or function) is executed and the result of b is returned;
- If True, return the result of a;