DEV Community

front_end_shifu_2022
front_end_shifu_2022

Posted on

Logical operators(|| OR)

|| (OR)

the logical OR Return true If any of its arguments are true otherwise it returns false..
e.g.
alert( true || true ); // true
alert( false || true ); // true
alert( true || false ); // true
alert( false || false ); // false

If an operand is not a boolean, it’s converted to a boolean for the evaluation.

For instance, the number 1 is treated as true, the number 0 as false
e.g.
if (1 || 0) {
alert( 'truthy!' );
}
in above the output is truthy.cause true||false return True.

Now lets talk about multiple OR’ed values:
result = value1 || value2 || value3;

The OR || operator does the following:
Evaluates operands from left to right.
For each operand, converts it to boolean. If the result is true, stops and returns the original value of that operand.
If all operands have been evaluated (i.e. all were false), returns the last operand.
e.g.
alert(''||0||1);//return 1 which is first truthy value
alert(null,0,undefined);// all falsy ,return last value.
*
let person1='';
let person2;
let person3='talha';
alert(person1||person2||person3||'no one');*
above output is talha.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay