0 day streak
javascript / beginner
Snippet

Destructuring Props and Objects

Destructuring allows you to unpack properties from objects into distinct variables. This makes code cleaner, especially when dealing with component props in Next.js.

snippet.js
javascript
1
2
3
const user = { username: 'markus', isAdmin: true };
const { username, isAdmin } = user;
console.log(username); // 'markus'
nextjs
Breakdown
1
const { username, isAdmin } = user;
Extracts 'username' and 'isAdmin' directly from the 'user' object.
2
username
The extracted value is now available as a local variable.