# Object Literal Property Value Shorthand

Il arrive souvent que le nom d'une propriété d'un "Object Literal" porte le même nom que la variable qui y sera associée : `{firstName: firstName}`.

Cela produit de la redondance :

```javascript
const firstName = 'Foo';
const lastName = 'BAR';

const user = {
    firstName: firstName,
    lastName: lastName,
    email: 'foo.bar@wishtack.com'
};
```

... mais grâce à la syntaxe "Object Literal Property Value Shorthand", on peut alléger le code :

```javascript
const firstName = 'Foo';
const lastName = 'BAR';

const user = {
    firstName,
    lastName,
    email: 'foo.bar@wishtack.com'
};
```

{% hint style="info" %}
A vous de définir votre style guide à ce sujet dans votre équipe.

Si l'écosystème JavaScript est nouveau pour l'équipe, il vaut mieux éviter ce genre de raccourcis.
{% endhint %}

{% hint style="warning" %}
Méfiez-vous des éditeurs qui n'arrivent pas à "refactor" les "object shorthands".

Chez Wishtack, nous nous sommes interdits leur utilisation jusqu'au support de ce refactoring par IntelliJ / WebStorm.

![Object Literal Property Value Shorthand refactoring avec IntelliJ](/files/-LASKiNvzlOT9dTjo0iG)

![Object Literal Property Value Shorthand refactoring fail avec VSCode](/files/-LASLeu7uJdSP0BgS9l0)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide-angular.wishtack.io/ecmascript-6+/syntactic-sugar/object-literal-property-value-shorthand.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
