DEV Community

front_end_shifu_2022
front_end_shifu_2022

Posted on

logical operater(&&And)

&& (AND)

In classical programming, AND returns true if both operands are true.otherwise its false.

alert( true && true ); // true
alert( false && true ); // false
alert( true && false ); // false
alert( false && false ); // false
e.g.
prompt(1&&0); //return 0

Now lets talk about multiple AND values:
result = value1 && value2 && value3;
The AND && operator does the following:

Evaluates operands from left to right.
For each operand, converts it to a boolean. If the result is false, stops and returns the original value of that operand.
If all operands have been evaluated (i.e. all were truthy), returns the last operand.

e.g.
prompt(null && 1 && 2);// output is null.
prompt(1 && 2 && "ppp");// output is ppp.

let person1=0;
let person2;
let person3='talha';
alert(person1||person2||person3||'no one');*
above output is 0.

Top comments (0)