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

Getting Started With Storybook Without a JavaScript Framework

Book on wooden path

8 Simple Steps: Set Up a Project With Tailwind CSS, Next.js 10, and PurgeCSS

Man using leafblower

Angular Component Communication

Creating a data component with Apollo Link

React UI Update (Circular Diagram)

Brief Introduction To Set In Javascript

When the World’s Greatest Boxer faced cruel Racism.

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

Using JavaScript and window.postMessage() for Safe Cross-Domain Communication

Logical OR in JavaScript

Const myFirstJavascriptBlog = “Declaring Variables”

How global TypeScript utilities work under the hood — Required<Type>