# ES6 Object Literal Property Value Shorthand in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jun 10, 2020, updated Oct 9, 2022. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-object-property-shorthand

> Learn how to use the object literal property value shorthand to create an object in JavaScript.

In JavaScript, we are used to constructing an [object](https://attacomsian.com/blog/objects-prototypes-classes-javascript#objects) by using the literal syntax `{...}` where each key-value pair is defined explicitly. We usually use the same object key names as the existing variables used as values.

Let us look at the following example:

```javascript
var name = 'John Doe'
var email = 'john.doe@example.com'
var age = 25

var user = {
  name: name,
  email: email,
  age: age
}
```

As you can see above, the properties have the same names as the variables. The **object literal property value shorthand** was introduced in ES6 to shorten the object initialization.

It allows us to define an object whose keys have the same names as the variables passed in as properties by simply passing the variables:

```javascript
let name = 'John Doe'
let email = 'john.doe@example.com'
let age = 25

let user = { name, email, age }

console.log(user)

// {
//     name: 'John Doe',
//     email: 'john.doe@example.com',
//     age: 25
// }
```

The property value shorthand syntax automatically converts each variable to a key-value pair with the variable name as a property key and the variable value as a property value.

You can also combine both regular properties and shorthands in the same object. This is especially useful when you want to assign a different key name to a property than the variable name:

```javascript
let user = { name, userEmail: email, age }

// {
//     name: 'John Doe',
//     userEmail: 'john.doe@example.com',
//     age: 25
// }
```
