javascriptecmascript-6javascript-objectsshorthand

Object shorthand notation { a, b } is accepted by some browsers, but not others – is this valid JavaScript?


My very simple question is that I want to know if the following code is legal:

var a = 1;
var b = 2;
var c = {a,b};

Backstory: I can use the above code in Chrome, but IE 11 does not seem to work with this. Is there a similar (i.e. concise) way to do this that will work in all (recent) browsers?


Solution

  • It's valid ES2015. Next most concise thing for engines that don't support that is regular {a: a, b: b}.