← Back to release summary

JavaScript optional chaining

Category
JavaScript
Type
New or changed feature
Status
Enabled by default (Chrome 80)
Intent stage
Start prototyping

Summary

Provides safe access to descendent object members with parents that may or may not be null. This applies to objects as well as functions. For example, consider an object reference with three levels such as a.b.c. Testing for the existence of c would previously require nesting said test inside a test for b. This change allows you to test for c directly without an error being thrown when b is null.

Motivation

Optional Chaining reached Stage 3 at the July 2019 TC39 meeting.

Standards & signals

Docs: https://v8.dev/features/optional-chaining https://docs.google.com/document/d/1k7WuOEU6Bi7WwL5sHFLthxS7_jkG3ao3NsbFJ5DNwtQ/edit

Explainers: https://v8.dev/features/optional-chaining https://docs.google.com/document/d/1k7WuOEU6Bi7WwL5sHFLthxS7_jkG3ao3NsbFJ5DNwtQ/edit https://github.com/tc39/proposal-optional-chaining

View on chromestatus.com