javascript / beginner
Snippet
Object Property Shorthand
When creating an object, if the property name and the variable name are the same, you can just write the name once. This makes code cleaner and is very common when passing props or managing state.
snippet.js
1
2
3
4
5
const title = "Hello";const author = "Markus";const book = { title, author };// Same as { title: title, author: author }
react
Breakdown
1
const book = { title, author };
Creates an object using the variables 'title' and 'author' as both keys and values.