||

If the value on the left-hand side of the logic or operator is Boolean converted to false, return the value on the right-hand side (regardless of whether the right-hand value is true or false)

If the value on the left-hand side of the logic or operator is Boolean converted to true, the value on the left-hand side is returned. If both operands are null (NaN/undefined), null (NaN/undefined) is returned.

console.log( true || true ); // true
console.log( 123 || 'China'); / / 123
console.log( false || true ); // true
console.log( true || false); // true
console.log(1 || 0); / / 1
console.log(undefined || 0); / / 0
console.log(null || 1); / / 1
console.log(' ' || 1); / / 1
console.log(0 || 1);
Copy the code
&&

If the value on the left of the logic and operator is converted to true, the value on the right is returned (regardless of whether the value on the right is true or false)

If the value to the left of the logical and operator is Boolean converted to false, the value on the left is returned, but if the value to the left of the logical and is null/NaN/undefined, the result is NULL /NaN/undefined.

console.log( true && true ); // true
console.log( 123 && 'China'); / / China
console.log( false && true ); // false
console.log( true && false); // false
console.log(1 && 0); / / 0
console.log( undefined && 0); // undefined 
console.log(null && 1); // null
console.log(' ' || 1); / /"

Copy the code
??
null ?? 'huli' // huli
undefined ?? 'huli'  // huli
' ' ?? 'huli' / /"[]????'huli' / / []({})??'huli'  / / {}
NaN ?? 'huli' // NaN
false ?? 'huli' // false
0 ?? 'huli'  / / 0When the left-hand operand is zeronullorundefined, returns its right-hand operand, otherwise returns the left-hand operand.Copy the code
?? =
const a = { duration: 50}; a.duration ?? =10;
console.log(a.duration);
// expected output: 50a.speed ?? =25;
console.log(a.speed);
// expected output: 25The logical null assignment operator (x?? = y) nullish (nullundefined)Copy the code
| | =
const a = { duration: 50, title: '' }; a.duration ||= 10; console.log(a.duration); // expected output: 50 a.title ||= 'title is empty.'; console.log(a.title); // Expected output: "title is emptyCopy the code
&& =
let a = 1; let b = 0; a &&= 2; console.log(a); // expected output: 2 b &&= 2; console.log(b); // Expected output: 0 Expected output: 0Copy the code
.?

The optional chain operator (? .) allows you to read the value of a property located deep in the chain of connected objects without explicitly validating that each reference in the chain is valid. ? The. Operator functions like the. Chain operator, except that it does not cause errors when references are nullish (null or undefined), and the short-circuit returns undefined. When used with a function call, returns undefined if the given function does not exist.

const adventurer = { name: 'Alice', cat: { name: 'Dinah' } }; const dogName = adventurer.dog? .name; console.log(dogName); // expected output: undefined console.log(adventurer.someNonExistentMethod? . ()); // expected output: undefinedCopy the code
!

! Variables can be converted to Boolean type, null, undefined, and empty string are true, the rest are false.

!' '=true
!0=true
!null=true
!undefined=true
Copy the code
!!!!!

A!!! Is to convert an object to a Boolean and invert it. Two! Is invert a Boolean value, which is equivalent to converting a non-Boolean value to a Boolean value. Null, undefined, 0, and “are all flase.

console.log(!!undefined)//false null, undefined will be converted to false.
console.log(!!null)//false 
console.log(!!0)//false A numeric type that converts 0 to false and the rest to true.
console.log(!!"")//fase is a string value that converts null values ("") to false and the rest to true.
Copy the code
~ ~

Double flying operator

console.log(~~4.3) / / 4
Copy the code