Logical OR in JavaScript
Just use |
(Bitwise OR
):
function first(){
console.log("First function");
return true;
};
function second(){
console.log("Second function");
return false;
};
console.log(!!(first()|second()));
Read more about logical operators (||
, !!
, etc...) and bitwise operators (|
, &
, etc...) in JavaScript.
You could call all functions by collecting the values and then check the values.
function first(){
console.log("First function");
return true;
}
function second(){
console.log("Second function");
return false;
}
console.log([first(), second()].some(Boolean));
function logicalOr(a, b) {
return a || b;
}
...
logicalOr(first(), second());
If you call this with functions they evalualed before reaching the or statement.