Backbencher.dev

JS Daily 10 - Logical OR

Last updated on 30 Nov, 2020

What is the output of following code?

const result = false || "Hello";
console.log(result);
----o----

Output is "Hello". Output is not true as in some other programming languages.

Logical OR operator returns the deciding value in the logical chain. Here, the first value is false. So, the OR operator needs to check the next value. The next value, "Hello" is a truthy value that makes the overall OR statement true. Therefore "Hello" is returned and assigned to result.

If all the values in the logical OR statement is falsy, then result will be false.

--- ○ ---
Joby Joseph
Web Architect