Concept Flow - Object creation
Start
Define object using {}
Add properties and values
Use object in code
Access or modify properties
End
This flow shows how an object is created, properties are added, and then accessed or changed.
const person = { name: 'Anna', age: 25 }; console.log(person.name); person.age = 26; console.log(person.age);
| Step | Action | Object State | Output |
|---|---|---|---|
| 1 | Create object person with properties name='Anna', age=25 | { name: 'Anna', age: 25 } | |
| 2 | Access person.name | { name: 'Anna', age: 25 } | Anna |
| 3 | Update person.age to 26 | { name: 'Anna', age: 26 } | |
| 4 | Access person.age | { name: 'Anna', age: 26 } | 26 |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| person | undefined | { name: 'Anna', age: 25 } | { name: 'Anna', age: 26 } | { name: 'Anna', age: 26 } |
Object creation in JavaScript:
- Use curly braces {} to create an object.
- Add properties as key: value pairs.
- Access properties with dot notation (obj.key).
- Modify properties by assigning new values.
- Objects hold data as named properties.name and value "Alice"?{ key: value }.name and value "Alice" should be inside curly braces separated by a colon.{}.{}, which is the correct syntax. Others use parentheses, array brackets, or invalid syntax.const person = { name: "Bob", age: 30 };
console.log(person.name);person.name accesses the value of the key name in the object.namename is the string "Bob".const car = { brand = "Toyota", year: 2020 };:, not an equals sign =.brand = "Toyota" which is invalid syntax for object properties.student with keys name, age, and grades (an array). Which code correctly creates this object?grades is an array. const student = { "name" = "Eva", "age" = 22, "grades" = [90, 85, 88] }; uses equals signs which is wrong. const student = [ name: "Eva", age: 22, grades: [90, 85, 88] ]; uses array brackets instead of curly braces. const student = { name: "Eva", age: "22", grades: "90, 85, 88" }; uses a string for grades instead of an array.Pass the test and this pattern moves unknown