---
title: "Object property shorthand"
url: "https://blog.beyondthecloud.dev/tips/object-property-shorthand"
category: "JavaScript"
published: "2024-06-07"
---

# Object property shorthand

It applies only when the property name is the same as the name of the variable that stores a value.

### JavaScript Property Definitions Shorthand

To put variables into an object you can do something like that:

```javascript
import edit from '@salesforce/label/c.Edit';
import save from '@salesforce/label/c.Save';

const labels = {
    edit: edit,
    save: save
};

export default labels;
```

There is a shorter notation available to achieve the same:

```javascript
import edit from '@salesforce/label/c.Edit';
import save from '@salesforce/label/c.Save';

const labels = {
    edit,
    save
};

export default labels;
```

It applies only when the property name is the same as the name of the variable that stores a value.

```javascript
showToast(title, message, variant) {
    this.dispatchEvent(
        new ShowToastEvent({
            title: title,
            message: message,
            variant: variant
        })
    );
}
```

```javascript
showToast(title, message, variant) {
    this.dispatchEvent(
        new ShowToastEvent({
            title,
            message,
            variant
        })
    );
}
```
