Written in front of the knowledge:
Boolean cast:
Except for Nan, null, "", Undefined, 0, function, which are false, the others are true;
About conversion, and so I'll write another one, dedicated to string, int, and Boolean conversions.
symbols for short-circuit operations: | | &&! or with non-
the principle of short-circuit operation: when there are more than one expression, the value of the expression on the right is no longer evaluated when the left expression value can determine the result.
Rules for short-circuit operations:
&& find a fake, first look at the value of the first expression, if the first expression is not a Boolean type, cast to a Boolean type, if the conversion is false, the first value is returned (not the cast value), otherwise the second value is returned
|| For real, first look at the value of the first expression, if the first expression is not a Boolean type, cast to a Boolean type, and true after the conversion, returns the first value (not the value after being cast), otherwise returns the second value
! Non, look at the value of the expression, if the value of the expression is not a Boolean type, cast to a Boolean type, or True to return false, otherwise true.
Examples of short-circuit operations:
JavaScript code:
<script>Console.log ("& of short-circuit operations | Compares only the first expression and determines which value is returned by the first expression and the operation symbol"); Console.log ("&& Test"); Console.log ("&& for a holiday"); Console.log (true&&true); Console.log (true&&false); Console.log (false&&true); Console.log (false&&false); Console.log (true&& "ABS");//directly displays the value of the second expression absConsole.log (false&& "ABS");//directly displays the value of the first expression falseConsole.log ("" && "abs");//Nothing is displayed because the first expression is false after a Boolean cast, so the first value is displayedConsole.log ("abs" && "Qwe");//Direct Display QweConsole.log ("|| Test); Console.log ("|| Find the real "); Console.log (true||true); Console.log (true||false); Console.log (false||true); Console.log (false||false); Console.log (true||" ABS ");//Direct Display TrueConsole.log (false||" ABS ");//Direct Display ABSConsole.log ("| | |" ABS ");//Show ABSConsole.log ("abs" | | " Qwe ");//Show ABSConsole.log ("! Test"); Console.log (!true); Console.log (!false); Console.log (!" ABS ");//String ABS After Boolean cast is True,!true is falseConsole.log (! "");//string is false after a Boolean cast,!false is true</script>
Console:
2016.7.29 Short circuit operation (logic operation is the most common one in short-circuit operation)