Abbreviated notation for variable assignments
It is known that it is possible to create properties of an object based on a variable and its value, the procedure used was as follows:
|
1 2 3 4 5 6 7 8 9 10 |
var a = 'foo', b = 42, c = {}; var objekat = { a: a, b: b, c: c }; // object.a returns 'foo' .... |
Now with the new standard we can shorten this:
|
1 2 3 4 5 6 7 8 9 |
var a = 'foo', b = 42, c = {}; var objekat = { a, b, c }; |

Abbreviated method definition notation
Defining an object method no longer requires the function keyword and a colon. So now instead of:
|
1 2 3 4 5 6 |
osoba= { ime: "Pera", stampajIme: function() { console.log(this.ime); } } |
we can use the abbreviated notation:
|
1 2 3 4 5 6 |
osoba= { ime: "Pera", stampajIme() { console.log(this.ime); } } |
Permitted use of computed property
With the new standard it is allowed to use computed values for properties:
|
1 2 3 4 5 6 7 8 9 10 |
var i = 0; var a = { ['foo' + ++i]: i, ['foo' + ++i]: i, ['foo' + ++i]: i }; console.log(a.foo1); // 1 console.log(a.foo2); // 2 console.log(a.foo3); // 3 |
And even:
|
1 2 3 4 5 6 |
var param = "size"; var config = { ['mobile' + param.charAt(0).toUpperCase() + param.slice(1)]: 4 }; console.log(config); // Returns{mobileSize: 4} |
Duplicate properties are no longer error
Before the ES2015 standard, the compiler returned an error if an object property was duplicated, with the new standard it is now possible:
|
1 2 3 |
var a = { x: 1, x: 2}; console.log(a.x); // Returnsposlednju value a to je broj 2 |

