Logical operators in JavaScript

·

1 min read

Operator Syntax Description
Logical AND expr1 && expr2 If expr1 can be converted to true, returns expr2; else, returns expr1.
Logical OR expr1 || expr2 If expr1 can be converted to true, returns expr1; else, returns expr2.
Logical NOT !expr Returns false if its single operand can be converted to true; otherwise, returns true.
Examples of expressions that can be converted to false are:
  • null;
  • NaN;
  • 0;
  • empty string ("" or '' or ``);
  • undefined.
Operator precedence:
  • && > ||