Properties, methods, and nested data
This lesson applies Objects concepts to code you can run and adapt.
✓ What you will learn in this topic
- Explain key Objects concepts.
- Read and adapt the examples.
- Apply the idea to a small real interface or data task.
Concept explanation
Object literals, properties and methods, nested data, access, mutation, destructuring, Object methods, and iteration.
These concepts appear in everyday interfaces and data transformations; understanding the trade-offs helps you choose a reliable implementation.
Syntax
The examples use standard ECMAScript syntax. Run console examples in a browser console or Node.js; DOM examples require a browser page containing the referenced elements.
Example 1: a small experiment
Run this compact example to observe the core rule before applying it to a larger feature.
const member = { name: 'Asha', active: true };
const { name } = member;
console.log(name);Expected output: Asha
Why it is useful: A small experiment makes the value or behavior easy to inspect.
Example 2: a practical feature
This example models a small piece of application behavior. Adapt its values and inspect what changes.
const inventory = { pens: 12, books: 5 };
for (const [item, count] of Object.entries(inventory)) {
console.log(item + ': ' + count);
}Expected output: pens: 12, then books: 5
Why it is useful: The same pattern can be extended into a real feature without tying the entire application to one large block of code.
Common mistakes
Destructuring a missing property gives undefined. Supply a default when a value may be absent.
Best practices
Use dot notation for fixed property names, bracket notation for dynamic keys, and Object.entries() for key/value iteration.
Practice exercise
Represent a course with a title, nested instructor details, and a method that formats a label.
Lesson summary
Object literals, properties and methods, nested data, access, mutation, destructuring, Object methods, and iteration.
Knowledge check
Which statement best describes an important idea in Objects?
Show explanation
Object literals, properties and methods, nested data, access, mutation, destructuring, Object methods, and iteration.
Practical example
javascriptconst inventory = { pens: 12, books: 5 };
for (const [item, count] of Object.entries(inventory)) {
console.log(item + ': ' + count);
}
Expected result:
pens: 12, then books: 5
Hands-on practice task
Represent a course with a title, nested instructor details, and a method that formats a label.
In this section
Other lessons in Objects
Broaden your knowledge
Related learning topics
CSS
Learn to style, lay out, and adapt interfaces with a complete course from CSS foundations through advanced responsive architecture.
HTML
Learn to structure accessible, meaningful web pages with a complete HTML course from first document to professional application patterns.