Question 8
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const o = { z: 1, 10: 1, a: 1, 2: 1 };
console.log(JSON.stringify(o));
- A {"z":1,"10":1,"a":1,"2":1}
- B {"2":1,"10":1,"z":1,"a":1} Correct
- C {"10":1,"2":1,"z":1,"a":1}
- D {"a":1,"z":1,"2":1,"10":1}
Correct Answer: Option B
Integer-like keys come first in ascending numeric order (2 before 10), then string keys in insertion order (z, a).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!