Under normal circumstances&&And|This is relatively simple and will not be discussed here.
Prepare two objects for the following discussion.
VaRAlice = {
Name:"Alice",
Tostring:Function(){
Return This. Name;
}
}
VaRSmith = {
Name:"Smith",
Tostring:Function(){
Return This. Name;
}
}
in JavaScript , for && not only available for Boolean type, it does not only return Boolean type result.
L If the first operand is Boolean type, and the value is false , then return directly false .
LIf the first operand isBooleanType, and the value isTrueAnd the other operand isObjectType, the object is returned.
LIf both operands areObjectType. The second object is returned.
LIf any operand isNull, Then, returnNull.
LIf any operand isNan, Then returnNan.
LIf any operand isUndefinded, Then returnUndefined.
Alert (False& Alice); // false
Alert (True& Alice); // Alice
Alert (Alice & Smith); // Smith
Alert (Smith & Alice); // Alice
Alert (Null& Alice); // null
Alert (Nan & Alice); // Nan
Alert (undefined & Alice); // undefined
Alert (Alice & undefined); // undefined
For|It is not only usedBooleanType, not only returnsBooleanType.
In fact,Null,Undefined,NanWill be viewedFalse. The object is treatedTrue.
L If the first operand is Boolean type, and the value is true , Returns true .
L If the first operand is Boolean type, and the value is false , the second operand is Object , the Object object is returned.
LIf both operands areObjectType, the first object is returned.
LIf both operands areNull, Then, returnNull.
LIf both operands areNan, Then returnNan.
LIf both operands areUndefined, Then, returnUndefined.
Alert (False| Alice); // Alice
Alert (True| Alice); // true
Alert (Alice | Smith); // Alice
Alert (Smith | Alice); // Smith
Alert (Null| Alice); // Alice
Alert (Alice |Null); // Alice
Alert (Null|Null); // Null
Alert (Nan | Alice); // Alice
Alert (Alice | Nan); // Alice
Alert (Nan | Nan); // Nan
Alert (undefined | Alice); // Alice
Alert (Alice | undefined); // Alice
Alert (undefined | undefined); // undefined