The optional chaining operator (?.) is used to safely access deeply nested object properties without throwing errors if a reference is null or undefined.
It was introduced in ES2020.
1.Basic Syntax
- ?. stops the evaluation if the value before it is null or undefined
- Returns undefined instead of throwing an error
2.Example: Accessing Nested Properties
Without optional chaining:
