Tin mới
JavaScript: Scripting language
Web APIs: Programming interfaces
Structuring content with HTML module
Dynamic scripting with JavaScript module
Optional chaining with function calls
You can use optional chaining when attempting to call a method which may not exist. This can be helpful, for example, when using an API in which a method might be unavailable, either due to the age of the implementation
Optional chaining with function calls
You can use optional chaining when attempting to call a method which may not exist. This can be helpful, for example, when using an API in which a method might be unavailable, either due to the age of the implementation
Optional chaining with expressions
You can also use the optional chaining operator with bracket notation, which allows passing an expression as the property name:
It is invalid to try to assign to the result of an optional chaining expression:
SyntaxError: tagged template cannot be used with optional chain
It is invalid to try to assign to the result of an optional chaining expression:
It is invalid to try to assign to the result of an optional chaining expression:
SyntaxError: new keyword cannot be used with an optional chain
It is invalid to try to assign to the result of an optional chaining expression:
Dealing with optional callbacks or event handlers
If you use callbacks or fetch methods from an object with a destructuring pattern, you may have non-existent values that you cannot call as functions unless you have tested their existence. Using ?., you can avoid this e
The nullish coalescing operator may be used after optional chaining in order to build a default value when none was found:
This page was last modified on May 22, 2026 by MDN contributors.