Syntax

JavaScript Optional Chaining Syntax

In JavaScript, optional chaining: reads a nested property without crashing on null — user?.address?.city

Quick Answer

Syntax
user?.address?.city
JavaScriptSyntax

Optional Chaining

Code example
user?.address?.city

Reads a nested property without crashing on null.

Learn More

How to optional chaining in JavaScript

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

JavaScript Optional Chaining Syntax

Use user?.address?.city.

Related Syntax References

Frequently asked questions

What is the JavaScript syntax for optional chaining?

Use this pattern: user?.address?.city

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