Or && and || and advanced uses, and implicit conversion and display conversion.

Or the Advanced Usage

console.log(true || true); //   true
console.log(true || false); //  true
console.log(false || true); //   true
console.log(false || false); //  false
console.log(0 || false); //  false
console.log(false || 0); //  0
console.log(0 || true); //true
console.log(true || 0); //true
console.log(1 || false); //1
console.log(false || 1); //1
console.log(1 || true); //1
console.log(true || 1); //true

        Summary: 0 is false, 1 true, the judge sentences, as long as one is true, the result returned is true, otherwise false. Execution order from top to bottom, and if it finds one result is returned from left to right and is no longer true true down implementation, if the first result is false, then keep looking down, know so far true, returns true, If not true, the final result is a false return (false or 0)

And the Advanced Usage

console.log(true && true); // true
console.log(true && false); // false
console.log(false && true); // false
console.log(false && false); // false
console.log(0 && false); // 0
console.log(false && 0); // false
console.log(0 && true); //0
console.log(true && 0); //0
console.log(1 && false); //false
console.log(false && 1); //false
console.log(1 && true); //true
console.log(true && 1); //1
console.log(2 && true); //true
console.log(true && 2); // true
console.log("" && true); // ""
console.log(true && ""); // ""
console.log("a" && true); // true
console.log(true && "a"); // "a"
console.log({} && true); // true
console.log(true && {}); // {}
console.log([] && true); // true
console.log(true && []); // []
console.log(null && true); // null
console.log(true && null); // null
console.log(undefined && true); // undefined
console.log(true && undefined); // undefined
console.log(NaN && true); // NaN
console.log(true && NaN); // NaN

           Summary: 0 is false, 1 true, the judge sentences must be both conditions are true, returns true, otherwise returns false, execution order from top to bottom, left to right from the time the direct return, the first condition is not met 0 or false value to the left, down is not executed, the first condition is true or 1, continue to look at a second condition, if the second condition is also true or 1, the value of the right return true or 1 , if the second condition is not satisfied, the value of 0 or false is returned to the right,

          If the compared value is non-0 is the true, that is above 1 can be replaced by any number of non-zero, the same result.

          If characters are compared, then the "" Empty is the true, that is "" empty, then the execution will be converted into a false accordance with the rules of false, but the result will be displayed as "" a null character, if the character "" there are no what words will be performed in accordance with the true, but the results still show the original characters

          If the array [], the object, functions {} When the determination is implicitly converted to true, follow the rules to true at run time, but the result was the previous expression
          if it is null, undefined, NaN judgment words, implicit when converted, all the operations carried out in accordance with the rules of false, but the result will still be the original expression,

Hermit conversion and display conversion (simple description)
Then the way, under what circumstances, will be converted hermit?
The following is performed when the operations of these operators will be converted implicitly:
arithmetic operators: + - * /%
comparison operators: == == === = <> <=> =!!?
Logical operators: && ||!
implicit conversion, when the conversion operation will occur after the operation is completed, according to the result of the judgment, showing the original value, will not change the original value
and convert it explicit?
Manually convert, change the value you want to convert, then calculation, at a glance, can see it, but we tend to err is implicit conversions among the

       Remember a good knock code.

Guess you like

Origin www.cnblogs.com/goodgoodstudyV/p/12302006.html