Question 2
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const o = {};
o[1] = "a";
o["1"] = "b";
console.log(Object.keys(o).length, o[1]);
- A 2 a
- B 2 b
- C 1 a
- D 1 b Correct
Correct Answer: Option D
The number 1 is converted to the string "1", so both assignments target the same property.
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!