Posted by Arjun on Sunday 26th July 2020

JavaScript - Nullish coalescing operator (??)

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.

const foo = null ?? 'default string';
// expected output: "default string"

const baz = 0 ?? 42;
// expected output: 0

const bar = undefined ?? 'default string';
// expected output: default string