The optional chaining operator (?.
) allows safe access to deeply nested object properties without worrying about null
or undefined
errors.
Example:
const user = { profile: { name: 'Alice' } };
console.log(user.profile?.name); // 'Alice'
console.log(user.address?.street); // undefined
Tags: basic, JavaScript, Operators
URL: https://www.tiktok.com/@jsmentoring/photo/7459817458866687264