0
0
Javascriptprogramming~10 mins

Object creation in Javascript - Step-by-Step Execution

Choose your learning style9 modes available
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.
Execution Sample
Javascript
const person = { name: 'Anna', age: 25 };
console.log(person.name);
person.age = 26;
console.log(person.age);
Creates an object 'person' with name and age, prints name, updates age, then prints new age.
Execution Table
StepActionObject StateOutput
1Create object person with properties name='Anna', age=25{ name: 'Anna', age: 25 }
2Access person.name{ name: 'Anna', age: 25 }Anna
3Update person.age to 26{ name: 'Anna', age: 26 }
4Access person.age{ name: 'Anna', age: 26 }26
💡 All steps completed, object created and properties accessed/modified.
Variable Tracker
VariableStartAfter Step 1After Step 3Final
personundefined{ name: 'Anna', age: 25 }{ name: 'Anna', age: 26 }{ name: 'Anna', age: 26 }
Key Moments - 2 Insights
Why does person.name print 'Anna' but person.age changes from 25 to 26?
At step 2, person.name is accessed and prints 'Anna' as set initially. At step 3, person.age is updated to 26, changing the object state, so step 4 prints the new value 26.
Is the object person recreated when we change person.age?
No, the object is not recreated. Only the property age inside the existing object is updated, as shown by the same object reference in the variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output at step 2?
A25
BAnna
Cundefined
D26
💡 Hint
Check the Output column at step 2 in the execution_table.
At which step does the person.age property change?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the Action and Object State columns in the execution_table.
If we add a new property person.city = 'NY', what happens to the object state?
AThe existing object now includes city: 'NY'
BA new object is created
CThe object is deleted
DThe object properties remain unchanged
💡 Hint
Refer to how properties are added or changed in the variable_tracker and execution_table.
Concept Snapshot
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.
Full Transcript
This visual trace shows how to create a JavaScript object named person with properties name and age. First, the object is created with name 'Anna' and age 25. Then, accessing person.name prints 'Anna'. Next, the age property is updated to 26. Finally, accessing person.age prints the updated value 26. The object itself is not recreated when properties change; only the property values update. This helps beginners see how objects store and change data step-by-step.