javascript / beginner
Snippet
Safe Property Access with Optional Chaining
Optional chaining allows you to read the value of a property located deep within a chain of connected objects without having to check if each reference in the chain is valid.
snippet.js
javascript
1
const street = user?.address?.street;
nextjs
Breakdown
1
user?
Checks if the user object exists before continuing.
2
.address?
Checks if the address object exists before accessing the street.