title | description | weight | lastmod | draft | vimeo | emoji | video_length | quiz |
---|---|---|---|---|---|---|---|---|
Optional Chaining |
Call object properties safely |
23 |
2022-11-11 10:23:30 -0900 |
false |
773489916 |
⛓ |
6360 |
true |
Optional chaining ?
is a relatively new operator that was introduced in ES2020. It allows you to call object properties safely, without throwing an error. When calling properties without this operator, you many crash your applcation with the error Cannot read property 'foo' of undefined
.
const person = { };
const dude = person.name;
console.log(foo); // Uncaught TypeError: Cannot read property 'bar' of undefined
const dude = person?.name; // undefined