javascript

Use of ?? (Nullish Coalescing Operator) in Javascript

We can use Nullish Coalescing Operator in Javascript to ignore null value if there is any. If left side value of ?? is null or undefined it will take right side value of ??.

const user_name = null ?? 'Ankit';
// Output: "Ankit"

const number = 0 ?? 40;
// Output: 0

If left side value of ?? is not undefined or null it will take that as a value.

Was this helpful?