What's going on with JavaScript's OR operator?
扔个三星炸死你
扔个三星炸死你 2017-06-12 09:29:40
0
2
683

|| Shouldn’t the operator return true or false? Why does JavaScript return an object? What’s going on? Could you please help me explain

扔个三星炸死你
扔个三星炸死你

reply all(2)
三叔

Javascript logical operatorscan be used in non-Boolean environments.

Although the && and || operators can be used in non-Boolean environments, if their return values ​​can be converted to Boolean values, they can also be considered Boolean operations

(from logical operator)

For non-Boolean environments:

When there is one false, return the value on the false side
When there are two false, return the value before the operator (left side);
When there are two true, return the value after the operator (right side) value.

(derived from the return value of logical operations in JavaScript (logical AND &&, logical OR ||, logical NOT!))

学习ing

First of all, you need to know the false values ​​in js: 0, false, '', null, undefined, NaN
In combination or operation
When one.nextElementSibing is not any of the above values, next = one.nextElementSibing; otherwise it is equal to one. nextSibing

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template