JavaScript Lesson 6: Objects and JSON

JavaScript Lesson 6: Objects and JSON featured illustration

📎 This article includes 2 downloadable practice files ↓

⏱ 1 min read

📘 JavaScript Beginner Course · Lesson 6 of 8

Advertisement
In this article
  1. JSON
  2. Useful helpers
  3. Practice
  4. Continue learning
const order = { id: "SO-1001", customer: { name: "Iyer Stores", city: "Chennai" },
                items: [{ p: "Laptop", q: 2, r: 42000 }] };
order.customer.name;              // "Iyer Stores"
const json = JSON.stringify(order);   // text, to save or send
const back = JSON.parse(json);        // object again
const { customer: { city } } = back;  // destructuring

JSON

JavaScript Object Notation is plain text that looks like these objects. APIs, config files and many exports use it. Keys must be in double quotes; no trailing commas.

Useful helpers

Object.keys(o), Object.values(o), Object.entries(o); the optional chaining order.customer?.gstin returns undefined instead of crashing when a property is missing.

💡 console.table(arrayOfObjects) prints a neat table in the browser console or Node, great for checking data.

Practice

Run the script, then add a second item and print the order total.

Advertisement

📎 Practice files for this article

⬇ Download all 2 files (ZIP · 622 B)

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong