Can one set multiple properties inside an object literal to the same value?

An update to this (in terms of the latest JavaScript abilities) avoiding unwanted defined vars:

{
  let v;
  var obj = {
     "a": (v = 'some value'),
     "b": v,
     "c": v
  };
}

This will mean v won’t be defined outside the block, but obj will be.

Original answer

Another way of doing the same thing is:

var v;
var obj = {
     "a": (v = 'some value'),
     "b": v,
     "c": v
};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)