() is used to call a function that may not exist. However that semantics is debatable and may be changed. JavaScript | Optional chaining - GeeksforGeeks JavaScript operator: Optional chaining operator (`?.`) - Can I use Optional Chaining. JavaScript Optional Chaining - An Introduction - Keyhole Software boolean, defaults to false.. Why do small African island nations perform better than African continental nations, considering democracy and human development? You can also use optional indexing with arrays: And with dynamic property access. and ?? As we are using the proposal for quite some time now. Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff. Thanks for learning with the DigitalOcean Community. // Top function can be called directly, too. to implicitly check to be sure obj.first is not null or Data structures inside your application should indeed be designed to always adhere to the same strict schema, although even that isn't always the case. could have a debugging version which does the console.log for you in development only. If a top level key is not accessible, then: Because it's some response coming from the server without any type safety, maybe. . And thats all you need to know, consider yourself well informed on the topic, and start using that sweet sweet optional chaining! For example, if obj.first is a Falsy value that's not null or undefined, such as 0, it would still short-circuit and make nestedProp become 0, which may not be desirable. 2023 DigitalOcean, LLC. javascript Share Follow asked Feb 20, 2021 at 7:02 Matthew Barbara 3,684 2 21 32 Add a comment 2 Answers Sorted by: 3 I have a proposition, slap it into a babel plugin and just give people option - some (most?) Setting up .babelrc. Dynamic Import. I believe they are the most significant improvement to JavaScript ergonomics since async / await. I meant performance of babel-compiled optional chaining vs baseGet. Are you sure you want to hide this comment? Is it correct to use "the" before "materials used in making buildings are"? But for normal programming? I wonder what the performance implications of using something like this is. A chain of ?. explicitly test and short-circuit based on the state of obj.first before JavaScript Optional Chaining `?.` Explained - freeCodeCamp.org This prevents the error that would occur if you accessed Thanks for the info @danielroe. I think the same is to Nullish coalescing etc. Here's an example.