# JS Tip of the Day: Nullish Coalescing Operator

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-nullish-coalescing-operator/643181>\
**Category:** web dev\
**Created:** [February 15, 2020, 5:09pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-nullish-coalescing-operator/643181 "2020-02-15T17:09:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 15, 2020, 5:09pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-nullish-coalescing-operator/643181/1 "2020-02-15T17:09:42Z")

</div>

**Nullish Coalescing Operator**  
Version: ES2020  
Level: Intermediate

The nullish coalescing operator (`??`) is also new to ES2020. It works much like logical OR (`||`) except that it will short circuit (or return) for non-null, non-undefined falsy values such as false, 0, and empty strings whereas OR would not. This is useful for setting defaults that may include these kinds of values.

```auto
let initialValue = 0;
let x = initialValue || 1;
let y = initialValue ?? 1;
console.log(x); // 1
console.log(y); // 0

```

More info:

- [Nullish Coalescing Operator on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_Coalescing_Operator)
