Jichao Jichao - 1 year ago 112
Javascript Question

Javascript props assignment without key?

let text = 'how are you';
let foo = {
type : 'foo',

Why the key
is auto assigned, is there any reference on such syntax?

Answer Source

This is a shorter notation in ECMAScript 2015(ES6) Object initializer.

var a = "foo", 
    b = 42, 
    c = {};

var o = { 
  a: a,
  b: b,
  c: c

//ES6 shorter notation available to achieve the same:  
var o = { a, b, c };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download