Back to questions
JuniorTheoryCommon
What does the program print?
const o = { b: 1, 2: 1, a: 1, 1: 1 };
console.log(Object.keys(o).join(" "));1 2 b a
- Expecting
b 2 a 1, the order the keys were written in: integer-like keys such as2and1always come first, in ascending order. - Expecting
1 2 a b: only the integer-like keys are sorted; the other keys keep the order they were added in, sobstays beforea.
- Does
for…inover the same object visit the keys in the same order? - In what order would the keys come out if the object were a
Map?