Skip to content

Instantly share code, notes, and snippets.

@haryantowang09
Last active June 15, 2023 05:42
Show Gist options
  • Save haryantowang09/bc17455eca57041add9d4b542471d548 to your computer and use it in GitHub Desktop.
Save haryantowang09/bc17455eca57041add9d4b542471d548 to your computer and use it in GitHub Desktop.
Javascript Logical
a || b
in short, this is democracy, if one of them is a Yes man, we all yes man.
Read more
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR
a || b || c
How does this work to?
Thanks ChatGPT-san,
In JavaScript, the multiple pipe operator (||) is known as the logical OR operator.
It can be used to evaluate multiple expressions in a left-to-right order and returns the value of the first truthy expression encountered,
or the value of the last expression if none of the expressions are truthy.
const a = -2;
const b = 0;
const c = '';
d = a || b || c;
// so it take whatever as long as it's not 0,
// if there is number above 0, it will take above zero instead of < 0
console.log(a > 0 || b > 0);
// Expected output: true
console.log(d);
// so what is d?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment