1. It is used in the judgment of conditions
2. Note when assigning:
Var result = | a | b was established to determine whether a first, give the result a assignment, or give the result b assignment
Var result = a &&b; var result = a &&b; var result = a &&b
Practical use:
functionFn (x) {/ / not pass arguments or parameters passed is false, a default value for x x = x | | 0}Copy the code
Extension: ES6 syntax can be set to default:
function fn(x = 0) {
console.log(x)
}
Copy the code
And and or mixed use: 0 | | 1 & 2 | | 0 | | 3 & 2 | | 1 mixed use, calculate and first, or after. 1 & 2 to 2, 3 & 2 to 2, 0 | | 2 to 2, 2, or 0 to 2, 2, or 2, or 2, 2, or 1 and 2