Short circuiting with || :
Left-hand is truthy, return LHS without evaluating RHS. Left hand is falsy, return RHS.
console.log(true|| false) // true.
console.log(false|| true) // true.
console.log(5 || undefined) //5
console.log(undefined|| 5) //5
console.log(78|| 58) //78.
console. log(left() || right())
// if the left function returns a truthy value, then no need to evaluate the right function.
Note: || or: expression is commonly used to assign default values to variables. Let v1=prams.color || "gray ";
Short circuiting with && operator:
Left operand is truthy, return RHS. Left operand is falsy, return LHS without evaluating RHS. true && true // true. true && false // false. False && true // false. False && false // false.
Examples:
console.log(5 && undefined) // undefined
console.log(undefined && 5) // undefined
console.log(left() && right()) // right.