About object properties according to the spec.

I want to be sure I understand something.

let a = {};
a[0] = "foo"; //coerces 0 to "0" before assigning the property

but [[Get]]from 9.1.8 in the spec looks like this:

function get(p, receiver) {
  return ordinaryGet(this, p, receiver);
}
function ordinaryGet(o, p, receiver) {
  if (!isPropertyKey) throw new TypeError("InvalidKey");
  ...
}
function isPropertyKey(key) {
  return ["string", "symbol"].contains(typeof(key));
}

Where exactly does the type coercion happen? Seems like a number type should fail isPropertyKey.

It happens in the Runtime Semantics of MemberExpression [ Expression ]: https://tc39.es/ecma262/#sec-property-accessors-runtime-semantics-evaluation (step 6).

1 Like

Thanks for that. Depending on what you're looking for, the spec can be a really difficult read!