The ECMASCRIPT 6 (2015) have added a comfortable shortcut of literal objects definition in javascript.

Object Literal Property Value Shorthands, New feature of ES6

There are many ways to declare an object in javascript and some people rather the literal way instead the declaration way, for example :

// We declare the variable MyAuto literal
var MyAuto = {type:"Fiat", model:"500", color:"black"};
// Remember that the spaces and line breaks are not important
var Another = {
    firstName:"John",
    lastName:"Doe"
};

var other = new Object(); // It supposed to slow down the code and make it more complex

Now in the new ECMASCRIPT6 a new notation is available, this allows to set properties to an object without define a key value structure, we would be writing them as an array, play and analize the following example :

As you can see, the literal variables are stored automatically as key-value in our object ,the computed values (the key is declared in a string variable) are also available and the new syntax of the declaration of a function inside the object (which is very similar to Coffescript), we don't need to write "key is equal to function".

The new ES6 brings many interessant features that you can learn and you can read them here.


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors