JavaScript · Level 1 Data

Objects

Group a product's details in an object, read them by name and turn them into a short label for a shop page.

  • { key: value } object literals
  • obj.key and obj["key"]
  • Object.keys lists the keys
  • A const object's properties can still change

An object groups values under names. Read them with obj.key or obj["key"]. The trap: const only stops you replacing the object; its properties can still change.

const user = { name: "Ada", role: "admin" };
user.name;               // "Ada"
user["role"];            // "admin"
Object.keys(user);       // ["name", "role"]
user.role = "editor";    // allowed, even with const

Write describe(product) that returns "<name>: $<price>", e.g. describe({ name: "Book", price: 12 }) returns Book: $12.

solution.js
Test Suites Pending
Output