Nullish coalescing operator: ‘??’

result = (a !== null && a !== undefined) ? a : b;
let height = 0;alert(height || 100); // 100
alert(height ?? 100); // 0

Precedence

Summary

// set height=100, if height is null or undefined
height = height ?? 100;

--

--

--

Developer with 3 yrs of industrial experience in developing scalable web applications.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a ui-kit with PatternLab using Atomic Design Principles

Custom select with Vue.js

Day 21: Accessibility and Development.

Running a blog in a subdirectory on Squarespace

Web development with React — Youtube Clone

How You Should Not Write Code - JavaScript

Simple Angular app using ngrx 8+ store and effects factory methods

React/Redux Project: Creating a Gratitude Journaling Application

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhay Jain

Abhay Jain

Developer with 3 yrs of industrial experience in developing scalable web applications.

More from Medium

Why should you avoid using JSON.stringify with UseEffect?

NVM Express Primer

JavaScript Utility Methods in Detail

Learn how to build resilient JavaScript code by using TypeScript Narrowing