Optional Chaining

Optional Chaining: This feature allows you to access deeply nested property paths in an object without checking the existence of each level. Instead of writing multiple conditions to avoid getting undefined in case a property doesn’t exist, you can use optional chaining that automatically checks if the value is not undefined or null.


For example:

const car = { model: { name: 'BMW' } };

console.log(car?.model?.name); // "BMW"

console.log(car?.manufacturer?.name); // undefined



Comments

Popular posts from this blog

Abstract Classes and Interfaces

Arrow functions