Its called "optional chaining" operator. It moves from left to right. if it sees ?. it checks the left value if its undefined or null. if yes, it returns undefined and stops moving to the right. that means if b is already undefined it wont check the values on the right side

Answer from Ilijanovic on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Optional_chaining
Optional chaining (?.) - JavaScript | MDN
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.
🌐
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…
Discussions

[AskJS] Over-using optional chaining. Is this pattern common?
Optional chaining is great. I find it however quite frustrating that TC39 included the "optional call" syntax that you're illustrating. THAT is a terrible feature that should be avoided, IMO. Besides it looking weird (like a typo), one reason I dislike it so much is that it seems (to the reader) like it's checking if the function can be called, and only calling it if safe to do so. But that's not what it's doing. It's only checking if the callee is not-nullish. var isThisAFunction1 = null; var isThisAFunction2 = "oops"; // later isThisAFunction1?.(); // safely a no-op isThisAFunction2?.(); // Exception! More on reddit.com
🌐 r/javascript
25
5
January 18, 2021
ecmascript next - How does the JavaScript optional chaining(?.) operator works? - Stack Overflow
I was looking into the new JS optional chaining?. operator. It helps us from getting errors like this, TypeError: Cannot read property ‘x’ of undefined You can write const obj = {a: 1}; console.lo... More on stackoverflow.com
🌐 stackoverflow.com
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
[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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-optional-chaining
JavaScript Optional Chaining - GeeksforGeeks
Optional Chaining (ES2020) safely accesses properties or calls functions on null or undefined values.
Published   January 12, 2026
🌐
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?

🌐
JavaScript.info
javascript.info › tutorial › the javascript language › objects: the basics
Optional chaining '?.'
April 14, 2022 - 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 ?.
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.
🌐
Swift.org
docs.swift.org › swift-book › documentation › the-swift-programming-language › optionalchaining
Optional Chaining - Documentation | Swift.org
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
🌐
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 Forums
forums.swift.org › using swift
Optional chaining with operators - Using Swift - Swift Forums
February 2, 2022 - 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 ...
🌐
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.
🌐
TypeScript
typescriptlang.org › play › 3-7 › syntax-and-messaging › optional-chaining.ts
TypeScript: Playground Example - Optional Chaining
const artistBio = album?.artist?.bio; ... values (e.g. an empty string, 0, NaN, and, well, false). Optional chaining will only take null or undefined as a signal to stop and return an undefined. Optional Element Access Property access is via the . operator, the optional chaining ...
🌐
V8
v8.dev › features › optional-chaining
Optional chaining · V8
August 27, 2019 - What happens when db, user, or name is undefined or null? With the optional chaining operator, JavaScript initializes nameLength to undefined instead of throwing an error.
🌐
Marius Schulz
mariusschulz.com › blog › optional-chaining-the-operator-in-typescript
Optional Chaining: The ?. Operator in TypeScript — Marius Schulz
September 11, 2021 - TypeScript 3.7 added support for ... use this operator to descend into an object whose properties potentially hold the values null or undefined without writing any null checks for intermediate properties....
🌐
Google Groups
groups.google.com › a › chromium.org › g › chromium-dev › c › DHLSm05HHlo
Allow optional chaining operator in Chromium Web code
September 28, 2022 - Looking at https://chromium.googlesource.com/chromium/src/+/HEAD/styleguide/web/es.md it seems that the optional chaining operator (?.) is currently banned.
🌐
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
January 6, 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 ...