Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7cbb265

Browse files
authored
optional chaining
1 parent622978b commit7cbb265

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,25 @@ console.log(age);
390390
// expected output: "0"
391391
```
392392
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+
console.log(carColor);
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+
//undefined- no error
412+
413+
//You can use this syntax today using @babel/plugin-proposal-optional-chaining
414+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp