Logical Operators

Β·

1 min read

The Operator that gives either truthy or false value based on input.

There are three logical operator.

OR Operator(||)

AND Operator(&&)

Not operator(!)

  1. OR Operator

The rule of OR Operator is it always find the first truthy value not true value.

  • The symbol of OR Oprator is ( || )

eg-


false || undefined || 21
21(because 21 is the truthy value)


1000 || "Hello" || "John" || true || 
1000(beacuse first truthy value is 1000)


null || undefiend || NaN
NaN(because operator doesn`t have any option the answer will be NaN)
  1. AND Operator

Just the opposite of OR. AND is always looks for a first falsy value.

  • The symbol of AND Operator is ( && )

eg-


21 && 100 && false
false
  1. Not Operator

This operator is unary operator because it hve one oprand.

eg-

!"Hello"
false ("Hello" gets converted into boolean and give true because of not
           operator it will give the result false)

!undefined
true(When undefined converted to boolean it return false and inverse od false is true)

NOTEπŸ‘‡

truthy and falsy is a category of value but true itself is a value.

Thanks for reading😊😊

Β