logical operators in JavaScript

What you will learn here about javascript

  • logical operators in javascript

Logical operators used to connect two expressions. JavaScript supports following logical operators.

  1. Logical AND ( && )
  2. Logical OR ( || )
  3. Logical NOT ( ! )

1)Logical AND ( && )

Logical AND returns true only when both expressions returns true. If any one the expression returns false, Logical AND returns false.

if( 10<20 && 20<50) //this returns true

if( 100<20 && 20<50) //this returns false

2)Logical OR ( || )

Logical OR returns true only when either of expression returns true. If both expression returns false, Logical OR returns false.

if( 10<20 || 20<50) //this returns true

if( 100<20 || 20<50) //Even this returns true

if( 100<20 || 20<10) //this returns false

3)Logical NOT ( ! )

Logical NOT returns true if expression is false and returns false if expression is true

if( !(10<20)) //this returns false

if( !(100<20)) //this returns true


You may also like...