Chrome Extension

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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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

Was this helpful?
0 Comments