Syntax

JavaScript Nullish Coalescing Syntax

In JavaScript, nullish coalescing: uses a default when a value is null or undefined — const n = value ?? 0;

Quick Answer

Syntax
const n = value ?? 0;
JavaScriptSyntax

Nullish Coalescing

Code example
const n = value ?? 0;

Uses a default when a value is null or undefined.

Learn More

How to nullish coalescing in JavaScript

  1. Open your JavaScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

JavaScript Nullish Coalescing Syntax

Use const n = value ?? 0;.

Related Syntax References

Frequently asked questions

What is the JavaScript syntax for nullish coalescing?

Use this pattern: const n = value ?? 0;

Can I copy this JavaScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this JavaScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify