AND, OR, and NOT Operators in Javascript (Boolean Logic)

  • Post category:Javascript
  • Reading time:3 mins read

In this post, we will learn about the AND, OR, and NOT Operators in Javascript. This is an important topic and you will use boolean logic when writing complex, moderate, or easy code.

AND, OR, and NOT Operators in Javascript

Let’s understand AND, OR, and NOT operators.

AND Operator

AND operator is denoted by && in Javascript.

AND operator is true when all are true, no matter how many variables are there. See the below table (for 2 variables).

AND TRUE FALSE
TRUE TRUE FALSE
FALSE FALSE FALSE

OR Operator

OR operator is denoted by || in Javascript.

In the OR operator, if any one of the statements is true then it will give true no matter if other values are false.

OR TRUE FALSE
TRUE TRUE TRUE
FALSE TRUE FALSE

NOT Operator

NOT operator is denoted by ! in Javascript.

Suppose, if a value in a variable is true and if we put NOT operator in front of that variable then it will make that value as false. For example.

let isSun = true;

Now, if I put a NOT Operator in front of isSun variable then it will give false value.

console.log(!isSun);

The output of the above console.log() statement will print false in the console.

Share this