javascriptlogical-operators

Logical operators in JavaScript — how do you use them?


I don't understand how &&, ||, and ! work... both with bools and other data types. How do you use them?


Solution

  • All values in JavaScript are either “truthy” or “falsy”.

    Both operators will not evaluate any operands after the one the return. If all operands don’t match, they will evaluate to the last one.


    All values are truthy except the following, which are falsy: