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?
Similar Posts
- Nullish coalescing operator (??)
- How to use Ternary Operator in place of if else statements Javascript
- Javascript ES6 Spread Operator
- Use of logical operators to reduce if else statements Javascript
- How to use loop in React JSX
- Use image as chart datasets background Chart.js
- Use jQuery to check if a tab is active/inactive