In JavaScript, object shorthand syntax is a more concise way to define properties on objects. It was introduced to make object literals more
readable and expressive.
In the shorthand syntax, if a variable exists in the scope with the same name as the object key you’re defining, you can omit the key-value pair
and just write the variable name. The interpreter will automatically understand that the key and the variable are linked.
Using object shorthand syntax can make your code cleaner and easier to read. It can also reduce the chance of making errors, as you don’t have to
repeat yourself by writing the variable name twice.
let a = 1;
let myObj = {
a : a, // Noncompliant
fun: function () { // Noncompliant
//...
}
}
You can omit the property name and the colon if it is the same as the local variable name. Similarly, you can omit the function
keyword for method definitions.
let a = 1;
let myObj = {
a,
fun () {
//...
}
}