1

If you have an object where the properties are created by calling a function or a constructor, is the order of execution of these guaranteed?

Example:

const testObject = {
  foo: new Date().valueOf(),
  bar: new Date().valueOf()
};

console.log(testObject.foo > testObject.bar);

Is it ever possible that foo will be greater than bar?

1 Answers1

1

You can try it for yourself. In the latest firefox and chrome it appears to be evaluated as written:

let i = 0;
const counter = () => i++;

const testObj = {
    a: counter(),
    b: counter(),
    c: counter(),
    d: counter(),
    e: counter()
}

console.log(testObj)
Rubydesic
  • 3,386
  • 12
  • 27
  • This won't tell you if it's specified by the language or just a Firefox/Chrome implementation feature. – Barmar Sep 08 '20 at 20:36