Predict JSON.parse Output
Predict Output Easy
Question
What does this code print?
Code
const json = '{"name":"Ada","skills":["JS","Python"]}';
const obj = JSON.parse(json);
console.log(obj.name);
console.log(obj.skills[0]);
Hint
JSON.parse converts a JSON string into a JavaScript object.
Explanation
JSON.parse converts a JSON string into a JavaScript value. The parsed object has name: "Ada" and skills: ["JS", "Python"]. So obj.name is "Ada" and obj.skills[0] is "JS", each printed on its own line.
Related Resources
Related Lessons
- JavaScript Data Types
Learn about JSON.
Related Tools
- JSON Formatter
Format and parse JSON.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.