JavaScript Output Prediction Medium +20 XP
Object Keys
What does this log?
JavaScriptRead-only
const obj = { 1: "a", 2: "b", 3: "c" };
console.log(Object.keys(obj));What is the output?
Show answer and explanation
Answer: ["1", "2", "3"]
Object.keys() always returns strings, even if the keys were defined as numbers.
Hint: Object keys are always strings.
What this challenge tests
Output Prediction in JavaScript: objects, keys.