When accessing a property using bracket notation and optional chaining, you need to use a dot in addition to the brackets:

const value = a?.[b]?.c;

This is the syntax that was adopted by the TC39 proposal, because otherwise it's hard for the parser to figure out if this ? is part of a ternary expression or part of optional chaining.

The way I think about it: the symbol for optional chaining isn't ?, it's ?.. If you're doing optional chaining, you'll always be using both characters.

Answer from Nicholas Tower on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Optional_chaining
Optional chaining (?.) - JavaScript | MDN
July 8, 2025 - The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.
🌐
Reddit
reddit.com › r/javascript › [askjs] over-using optional chaining. is this pattern common?
r/javascript on Reddit: [AskJS] Over-using optional chaining. Is this pattern common?
January 18, 2021 -

Hi everyone!

I love optional chaining, i really do, but there are some cases where using this syntax damages the readability of the code. One of those cases is the following

function optionalFunction(){     
    console.log("works"); 
}  
// optionalFunction = undefined;  

optionalFunction?.(); 

While i understand this approach, i find it optionalFunction?.() harder to read as opposed to this

function optionalFunction(){     
    console.log("works"); 
}  
// optionalFunction = undefined;  

if(optionalFunction != undefined){     
    optionalFunction(); 
} 

I think i'd rather have a more readable and stronger check than ES6 magic when checking if an optional function is defined.

I believe that optional chaining fixes the problem of checking if a property of an object exists, and if exists, then get the value or keep going deeper in the object structure. But this syntax just looks weird for calling functions, it looks a lot like those "one line cleverness" code that sometimes people encounter.

What are your thoughts about this?

Discussions

Using optional chaining operator for object property access
TypeScript 3.7 now supports the optional chaining operator. Hence, you can write code such as: const value = a?.b?.c; I.e., you can use this operator to access properties of an object, where the o... More on stackoverflow.com
🌐 stackoverflow.com
What Is the Optional Chaining Operator, and How Does It Work?
TLDR: Optional Chaining Operator is for objects, not properties? https://www.w3schools.com/jS/js_2020.asp " The Optional Chaining Operator returns undefined if an object is undefined or null (instead of throwing an error)." /TLDR I’ve found a quiz question pretty confusing but I thought I ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
April 8, 2025
[AskJS] Is it a problem if the code base is filled with optional chaining?
A mantra in the Zig community that is applicable here: "Handled errors are better than exceptions, but exceptions are better than bugs" More on reddit.com
🌐 r/javascript
43
15
July 17, 2024
Optional chaining with operators - Using Swift - Swift Forums
Optional chaining can be used with methods, mutating methods, and assignment operators: var x: Int? = 0 x?.addingReportingOverflow(1) x?.negate() x? += 2 However, it currently cannot be used with non-assignment operators: x? + 3 // error: Value of optional type 'Int?' must be unwrapped to a ... More on forums.swift.org
🌐 forums.swift.org
0
December 5, 2021
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › objects: the basics
Optional chaining '?.'
There’s a little better way to write it, using the && operator: let user = {}; // user has no address alert( user.address && user.address.street && user.address.street.name ); // undefined (no error) AND’ing the whole path to the property ensures that all components exist (if not, the evaluation stops), but also isnt ideal. As you can see, property names are still duplicated in the code. E.g. in the code above, user.address appears three times. That’s why the optional chaining ?.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-optional-chaining
JavaScript Optional Chaining - GeeksforGeeks
JavaScript Optional chaining is a new feature introduced in ES2020 that simplifies the process of accessing properties nested within objects, especially when dealing with potentially null or undefined values.
Published   May 17, 2025
🌐
Swift.org
docs.swift.org › swift-book › documentation › the-swift-programming-language › optionalchaining
Optional Chaining | Documentation
This document is made available under a Creative Commons Attribution 4.0 International (CC BY 4.0) License · Swift and the Swift logo are trademarks of Apple Inc
Find elsewhere
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-3-7.html
TypeScript: Documentation - TypeScript 3.7
At its core, optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined. The star of the show in optional chaining is the new ?. operator for optional property accesses.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
What Is the Optional Chaining Operator, and How Does It Work?
April 8, 2025 - TLDR: Optional Chaining Operator is for objects, not properties? https://www.w3schools.com/jS/js_2020.asp " The Optional Chaining Operator returns undefined if an object is undefined or null (instead of throwing an er…
🌐
Swift Forums
forums.swift.org › using swift
Optional chaining with operators - Using Swift - Swift Forums
December 5, 2021 - Optional chaining can be used with methods, mutating methods, and assignment operators: var x: Int? = 0 x?.addingReportingOverflow(1) x?.negate() x? += 2 However, it currently cannot be used with non-assignment operators: x? + 3 // error: Value ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
The nullish coalescing operator treats undefined and null as specific values. So does the optional chaining operator (?.), which is useful to access a property of an object which may be null or undefined.
🌐
Swift.org
docs.swift.org › swift-book › LanguageGuide › OptionalChaining.html
Optional Chaining - Documentation | Swift.org
This content has moved; redirecting to the new location · This page requires JavaScript. Please turn on JavaScript and refresh the page
🌐
W3Schools
w3schools.com › js › js_2020.asp
W3Schools.com
Optional chaining not only works on object properties, but also on function calls and arrays. The Logical AND Assignment Operator is used between two values.
🌐
Medium
medium.com › @AlexanderObregon › optional-chaining-in-javascript-works-differently-than-you-think-216a8a43e45b
Optional Chaining in JavaScript Works Differently Than You Think
May 25, 2025 - Optional chaining gives you a way to safely walk through an object’s structure without crashing the program when something in the chain is missing. The idea is simple: stop early and return undefined if the value you're looking for doesn’t exist. But this isn’t just a neat shortcut. JavaScript treats the ?. operator as its own thing during parsing, with its own rules, timing, and behavior that don’t match regular property access.
🌐
DEV Community
dev.to › macsikora › what-is-wrong-with-optional-chaining-and-how-to-fix-it-3nno
What is wrong with optional chaining and how to fix it - DEV Community
May 1, 2020 - Edit: There is nothing wrong with optional chaining, the feature is related to idiomatic absence value in JS, and it is "null | undefined". The operator tries to address issues of previously used &&. This article tries to make a point that JS ...
🌐
Coda
community.coda.io › suggestion box
Optional chaining operator - Suggestion Box - Coda Maker Community
April 1, 2021 - Would be nice to have an optional chaining operator (similar to JavaScript’s ?., see Optional chaining (?.) - JavaScript | MDN), essentially that navigates the same as the regular . operator, with the exception that it short-circuits and returns ...
🌐
Roblox Developer Forum
devforum.roblox.com › feature requests › engine features
Optional chaining operator - Engine Features - Developer Forum | Roblox
January 22, 2021 - As a Roblox developer, it is currently too hard to access a property of something that is deeply nested. Currently, you have to check if the parent of the property you’re trying to access is nil. If you don’t, you have a risk of getting a nil error. TypeScript has an awesome feature called the optional chaining operator, which you can already use in Roblox-TS.
🌐
JetBrains
rider-support.jetbrains.com › hc › en-us › community › posts › 8096841842066-Javascript-Warn-on-optional-chaining
Javascript: Warn on optional chaining – Rider Support | JetBrains
October 14, 2022 - Hi, we are struggling with the usage of too modern features in javascript: They work fine on our dev's machines but fail on old devices in the real world. For example: optional chaining ("x?.SomePr...