How is the `&&` operator working?

Question

How is the && operator working?

Answer

When we use the && operator, also called the logical AND operator, if the left operand evaluates to true the right operand is returned, else the left operand is returned.

For example:

console.log(!true && 'hello world'); // here, the left operand evaluates to `false`, so `false` is logged to the console

console.log(true && 'hello world'); // here the left operand evaluates to `true`, so 'hello world' is logged to the console
1 Like