Object Literal Property Value Shorthand
It is common to create JavaScript objects using some local variables with the same names as the object properties ending up with something redundant like this:
const firstName = 'Foo';
const lastName = 'BAR';
const user = {
firstName: firstName,
lastName: lastName,
email: '[email protected]'
};
... but thanks to the Object Literal Property Value Shorthand, it can be written in a shorter manner:
const firstName = 'Foo';
const lastName = 'BAR';
const user = {
firstName,
lastName,
email: '[email protected]'
};
Beware of IDEs that can't refactor Object Literal Property Value Shortands.
At Wishtack, we didn't use them until the refactoring was possible with IntelliJ / WebStorm.


Last updated