Optional Calls and Index Access
Use optional chaining with calls and brackets.
Beyond Property Reads
Optional chaining also has forms for calling functions and accessing array or dynamic-key elements safely.
const obj = { greet: () => "hi" };
console.log(obj.greet?.()); // "hi"Optional Method Calls
The ?.() form calls a function only if it exists. If the method is nullish, it returns undefined instead of throwing.
const obj = {};
console.log(obj.greet?.()); // undefined, no errorAll lessons in this course
- Optional Chaining with the ?. Operator
- Nullish Coalescing with ??
- Combining ?. and ??
- Optional Calls and Index Access