Bitwise AND operator (&) in js
1. This operator performs a Boolean AND operation on its operands bit by bit, only the corresponding bits in the two operands When both are 1, this bit in the result is 1. It requires its operand to be an integer. If the operand is not an integer, it will try to convert it to a 32-bit integer. If it cannot be converted, NaN will be returned. .
// The operands are all integers
alert(9 & 9); // 9
alert(9 & 10); // 8< /p>
alert(1 & 3); // 1
// The operand can be converted to integer type
alert([9] & '9') ; // 9
alert([9] & ['10']); // 8
alert(1.25 & 3.25); // 1
// One or both operands cannot be converted to integer type
alert(1 & ['a']); // 0
alert({} & /\ d/); // 0
alert(NaN & NaN); // 0
alert(Infinity & Infinity); // 0
alert( NaN & Infinity); // 0
alert(null & null); // 0
alert(undefined & undefined); // 0
alert (null & undefined); // 0
//----------------------------
2.Logic && in JS
Example 1:
The following is a reference fragment: