In the non-JS

  Analyzing conditions are often used with js (&&) or (||) not (!)

  AND operation

  A false is false, the whole truth True, the case of false stops

var a=1&&2&&3;
       document.write(a);

  Such a result is that the output 3.

  When performing && operator, if the previous are true, it will continue to back, until the result of false or to the last one, for example:

var a=1&&0&&3;
       document.write(a);

  A current value of 0

  That is, if the case is false appearance of conditions, will not continue to perform backward, and returns the current value

  Said here about 6 returns false values: undefined, NaN, "" (the empty string), null, 0, false

 

  Short circuit statement

  && with characteristics to achieve, for example:

条件 && document.write(a);

  If the front && is false, then the latter would not be executed, corresponding to a short circuit, it can be used in the detection data values, data or variables && front fill, followed by use of the statement or variable value, if false behind the statement will not be executed

  

  OR

  It is true is true, all false and false, then stop Yuzhen

var a=1||0||3;
       document.write(a);

  The output is a current, compared with the operation, where the opposite

  If the first value is true, it returns the current value, and no longer execute the statement following

  if so:

 var a=''||0||2;
       document.write(a);

  Conditions of a current value returned is 2

  In other words, as long as the condition is false, execution will be back until the condition is true, stop executing backward, and returns the current value, if the last value is false, it will return the last value

  || may be in the process of writing code, different browser compatibility statement is used to achieve

 

  non-

  Whether it means, for example

var a=!'';
       document.write(a);

  Current returns true

  var a=!123;
       document.write(a);

  Current return value is false

  In both cases above, it is! After the latter value is converted to a Boolean value negated, the value returned, the return type is Boolean

 

Guess you like

Origin www.cnblogs.com/zhangcheng001/p/11110833.html