----- a little progress of the JS logical operators per day

1 with the operator &&

 

 

 And logical operators, the case where only two expressions, if the first boolean value is true expression is converted, directly returns a second value of the expression; If the first expression is false, directly the first expression of value is returned to the results of it.

Where more than two expressions, and so on, for example, only three expressions, the first expression is false, the direct return to the first value of the expression; when the first expression is true, read the first the second expression, the second expression is false, the second direct return value of the expression, the second expression is true, the third direct return value of the expression.

Therefore, the operator has a role of a short circuit interruption, occurs when the expression is false, the logic would interrupt.

Such as a short statement: 2> 1 && document. write ( "small wow handsome");

undefined null NaN "" 0 false six values ​​are converted to a Boolean false;

2. OR operator ||

IE and non-IE to take the event object is compatible with the wording:

div.click=function(e){

var event=e||window.event

 

Guess you like

Origin www.cnblogs.com/xbzxx/p/11876119.html