---
title: "Discussion on \"Optional chaining '?.' in JavaScript\" | Hashnode"
description: "Discussion on \"Optional chaining '?.' in JavaScript\". Hey Readers 👋\nIn this article, we’ll learn about the optional chaining (?.) that simplifies the way to access values through nested objects.\nWhat the heck is Optional chaining?  🥴\nThe optional chaining ?.  is a recent addition to the language which..."
url: "https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Optional chaining '?.' in JavaScript](https://inshaweb.hashnode.dev/optional-chaining-in-javascript?utm_source=hashnode&utm_medium=feed)

Hey Readers 👋 In this article, we’ll learn about the optional chaining (?.) that simplifies the way to access values through nested objects. What the heck is Optional chaining? 🥴 The optional chaining ?. is a recent addition to the language which...

Aug 13, 2021 · 4 min read · inshaweb.hashnode.dev  
Updated Aug 16, 2021  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#webdev](https://hashnode.com/tag/webdev)
-   [#javascript-modules](https://hashnode.com/tag/javascript-modules)

## Written by

[Insha Ramin](https://hashnode.com/@Inshaweb)

@Inshaweb · New Delhi, India

  
[View profile](https://hashnode.com/@Inshaweb)

DevRel | Simplifying tech concepts | Python, Blockchain, AI

Insha is a backend developer who specializes in building communities that drive shared value between developer-centric organizations and their users, aiming to enhance engagement, satisfaction, and retention. Proficient in Python and well-versed in web technologies including HTML, CSS, JavaScript, Django and SQL, she brings a dynamic skill set to the table.

## Responses 13

Markdown supported · ⌘↵ to post

[Vishal](https://hashnode.com/@Imvishp)

[Aug 15, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61193652ac5c985f36435ebe)

Wow insha,

Really like your blog, keep writing

Waiting for next 🙌👍😃

[SUMIT BHOWMICK](https://hashnode.com/@sumitbhowmick22)

[Aug 14, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61175bacf6ebde51f64fa025)

Amazingly explained ✌️💥

[Kritika Pattalam Bharathkumar](https://hashnode.com/@kritika-pattalam)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/6116817613a99e48922eed7f)

Well explained. Thank you!!

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 14, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/6116817613a99e48922eed7f#reply-6117ce32e9f08a51fd85fd0d)

Glad to hear that, Kritika 😊

[Deeksha Deepak](https://hashnode.com/@deeksha1502)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61167e7813a99e48922eed0c)

Thank you for this detailed explanation Insha, great work😃

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 14, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61167e7813a99e48922eed0c#reply-6117ce5de9f08a51fd85fd14)

Thank you, Deeksha! Glad you found it helpful💙

[Krishna Gupta](https://hashnode.com/@Krishnaa1006)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61167c2913a99e48922eec6c)

Great read, Detailed explanation 🔥🔥🔥

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61167c2913a99e48922eec6c#reply-61168aa51667fc4aab5dcf3b)

Thank you, Krishna💙

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/6116513173a6cd48b7f186ce)

Good one [Insha Ramin](https://hashnode.com/@Inshaweb), detailed explanation. I love using it now a lot.

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/6116513173a6cd48b7f186ce#reply-61168a8316b6034ad04b03cf)

Thank you so much for reading the article. Glad you liked it 🤗

[sintu sagar](https://hashnode.com/@Sintusagar)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611649ec73a6cd48b7f18621)

Best explanation ⚡⚡on this Topic , well done 👏

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611649ec73a6cd48b7f18621#reply-61168b1a1667fc4aab5dcf48)

Thank you for reading, Sintu. Glad to hear it was a great read for you 😃

[Bello Ololade](https://hashnode.com/@Ololade)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/6116486e13a99e48922ee61e)

Great read Insha 🔥

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/6116486e13a99e48922ee61e#reply-61168ac216b6034ad04b03e3)

Thank you so much, Olo🔥🤗

[Faheem Khan](https://hashnode.com/@FaheemKhancodes)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61163c5881a68f44e8a17c05)

I like detailed explanation. Well done, [Insha Ramin](https://hashnode.com/@Inshaweb)

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61163c5881a68f44e8a17c05#reply-61168ad616b6034ad04b03e9)

Thank you, Faheem. 🤗

[Ronnie](https://hashnode.com/@idrinkcss)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611630f416d7f34314377f82)

This is the best explanation, I've ever seen on this topic. Keep up the good work Ina. 😁😁😁

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 14, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611630f416d7f34314377f82#reply-6117ce7de9f08a51fd85fd1c)

Thank you, Ronnie. 😊🔥

[Musarrat Jabeen](https://hashnode.com/@Musarrat)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611615b81f1bd93c4f35c1d9)

Thanks for putting this. Loved the article and the way you explained the concept 🔥👏

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611615b81f1bd93c4f35c1d9#reply-6116256c894bad0f41a34ce8)

Ah, glad to hear this. Thank you for reading😊⚡

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61161423e249483e12110215)

Wonderful article.

**The optional chaining with function calls** stood out for me.

Thanks a lot for sharing.

### Suggestions:

In the example

```
let nestedProp = user.firstName?.lastName;
```

IMO I feel `lastName` cannot be gotten from `firstName`.

The example can be much clearer with `user.names.lastName` instead to make the example much realistic.

Overall I enjoyed every bit of the article 😊

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61161423e249483e12110215#reply-6116170a894bad0f41a34b47)

Thank you for the kind words, Samuel. Appreciate the suggestion. 😊

What I feel is :

Here it'll implicitly check to be sure **user.firstName** is not null or undefined before attempting to access **user.firstName.lastName**. If **user.firstName** is null or undefined, the expression automatically short-circuits, returning undefined.

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61161423e249483e12110215#reply-61161acf894bad0f41a34ba3)

Sure, I'm aware of the logic [Insha Ramin](https://hashnode.com/@Inshaweb)

But talking about the user object structure.

This means you're saying the user structure is 👇

```
const user = {

firstName: {
lastName: "Insha"
}

}
```

What I'm saying 👇

```
const user = {

names: {
firstName: "Insha",
lastName: "Ramin"
}

}
```

So we can check if the name object exist before accessing the firstName or lastName.

> I mean your lastName cannot be inside your firstName 😬.

I hope this explains the structure I'm talking about.

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/61161423e249483e12110215#reply-6116250390eeb80f1ac0d229)

Got your point. [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

I guess this got a little bit confusing but the case wasn't this. Anyways I appreciate you taking out the time to highlight this.😄

[Suprabha Supi](https://hashnode.com/@suprabhasupi)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611612ebe249483e121101fc)

Its quite detail explained [Insha Ramin](https://hashnode.com/@Inshaweb)

Thanks for sharing 🔥

[Insha Ramin](https://hashnode.com/@Inshaweb)

[Aug 13, 2021](https://hashnode.com/posts/optional-chaining-in-javascript/6116108ae249483e121101ab/comment/611612ebe249483e121101fc#reply-61162542894bad0f41a34cd9)

Thank you [Suprabha Supi](https://hashnode.com/@suprabhasupi). Glad you liked the article! 😊💙
