search

Home  >  Q&A  >  body text

What's going on with JavaScript's OR operator?

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

扔个三星炸死你扔个三星炸死你2773 days ago733

reply all(2)I'll reply

  • 三叔

    三叔2017-06-12 09:31:40

    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!))

    reply
    0
  • 学习ing

    学习ing2017-06-12 09:31:40

    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

    reply
    0
  • Cancelreply