Loading workspace environment...
Group related properties and attributes together using key-value pairs.
const user = { name: "Alice", age: 25 };Creates an object with two key-value pairs.user.nameDot notation to access property.user["age"]Bracket notation to access property.user.isOnline = true;Adds or updates a property on the object.const user = {
username: "ada_lovelace",
role: "Lead Engineer",
reputation: 980,
isActive: true
};
console.log("Username:", user.username);
console.log("Role:", user.role);
// Update reputation and add a new badge
user.reputation += 20;
user.badge = "Pioneer";
console.log("Updated Reputation:", user.reputation);
console.log("Earned Badge:", user.badge);Username: ada_lovelace
Role: Lead Engineer
Updated Reputation: 1000
Earned Badge: Pioneeruser.usernameReads the username field from the object.user.badge = "Pioneer";Adds a new key-value pair to user.const user = { name = "Bob" }; // SyntaxErrorconst user = { name: "Bob" }; // Use a colon between key and valueArchitectural Explanation: Inside object literals, use a colon : between the key and the value, not an equals sign =.
const book = {
title: "Clean Code",
author: "Robert Martin",
pages: 464
};
console.log(book.author);Create a product object with name ("Laptop"), price (1000), and discountPercent (15). Calculate and log the discounted price.