← BYTES
JavaScript·Intermediate·Ref: 3.2.13
What does optional chaining (`obj?.prop`) do?
Have a question about this video? Mention reference 3.2.13 when you contact us.
a.Throws a more descriptive error when `obj` is null/undefined
b.Only works on arrays, not plain objects
c.Short-circuits to `undefined` instead of throwing, if `obj` is null or undefined, avoiding a manual existence check before accessing `.prop`
d.Makes the property access run asynchronously
Optional chaining lets you write `user?.address?.city` and safely get `undefined` back the moment any link in the chain is null/undefined, instead of the expression throwing a TypeError partway through, replacing verbose manual `&&` chains of existence checks.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES3213#JavaScript