---
title: "Comment by Moshood Sikiru on \"How to use the Javascript Optional Chaining operator (?.)\" | Hashnode"
description: "This would still throw cannot read property color of undefined if yourObjectName does not exist: if (yourObjectName.color &amp;&amp; yourObjectName.color === &#"
url: "https://hashnode.com/posts/how-to-use-the-javascript-optional-chaining-operator/611698a81667fc4aab5dd09b/comment/61169d9916b6034ad04b0530"
---

[Discussion](https://hashnode.com/posts/how-to-use-the-javascript-optional-chaining-operator/611698a81667fc4aab5dd09b)

Comment [How to use the Javascript Optional Chaining operator (?.)](https://hashnode.com/posts/how-to-use-the-javascript-optional-chaining-operator/611698a81667fc4aab5dd09b)

[Moshood Sikiru](https://hashnode.com/@ayolan)

[Aug 13, 2021](https://hashnode.com/posts/how-to-use-the-javascript-optional-chaining-operator/611698a81667fc4aab5dd09b/comment/61169d9916b6034ad04b0530)

This would still throw **_cannot read property color of undefined_** if **_yourObjectName_** does not exist:

```
if (yourObjectName.color && yourObjectName.color === 'blue') {
  return 'Blue is cool';
}
```

**Perhaps you meant:**

```
if (yourObjectName && yourObjectName.color === 'blue') {
  return 'Blue is cool';
}
```

[Ugochukwu Ejiogu](https://hashnode.com/@lawrecks)

[Aug 13, 2021](https://hashnode.com/posts/how-to-use-the-javascript-optional-chaining-operator/611698a81667fc4aab5dd09b/comment/61169d9916b6034ad04b0530#reply-6116d4cc94173a4decbb9655)

That's true. Thanks for the observation!
