The && and || operator in Javascript has some quirks. It's best we clarify what it actually does since it's not easy to intuit for newcomers to the language despite being idiomatic.

The && and || evaluate to the value that is either to the left or right of the operator. (Not necessarily a true or false.)

What && does:

const truthy = 1;
const falsey = null;

console.log(truthy && falsey); // null
console.log(falsey && truthy); // null

If the left expression is falsey (false when coerced to a boolean), then return the left expression as the statement return value.

  1. Otherwise (if the left expression of && is truthy,) return the right side expression as the statement return value.

And for ||:

const truthy = 1;
const falsey = null;

console.log(truthy || falsey); // 1
console.log(falsey || truthy); // 1
  1. If the left expression is truthy, then return the left expression as the statement return value.
  2. If the left expression is falsey, then return the right expression as the statement return value.