We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent622978b commit7cbb265Copy full SHA for 7cbb265
README.md
@@ -390,3 +390,25 @@ console.log(age);
390
// expected output: "0"
391
```
392
393
+# Optional chaining
394
+```javascript
395
+
396
+constcar= {}
397
+constcarColor=car.name.color
398
+console.log(carColor);
399
+// error- "Uncaught TypeError: Cannot read property 'carColor' of undefined
400
401
+//In JavaScript, you can first check if an object exists, and then try to get one of its properties, like this:
402
+constcarColor= car&&car.name&&car.name.color;
403
404
+//undefined- no error
405
406
407
+//Now this new optional chaining operator will let us be even more fancy:
408
409
+constnewCarColor= car?.name?.color;
410
+console.log(newCarColor)
411
412
413
+//You can use this syntax today using @babel/plugin-proposal-optional-chaining
414
+```