JS Daily 5 - Boolean Value With Nullish Coalescing Operator

Last updated on 25 Nov, 2020

What is the output of following code?

const a = false;
const result = a ?? "Hello";

Output is false.

The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.

Default tendency is to return "Hello" because a is false. But ?? is explicitly built for null or undefined.

--- ○ ---
Joby Joseph
Web Architect