Posted by Arjun Arjun on Sunday 26th July 2020, 1 minute read

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

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.