Lesson 25 of 48
52%
JavaScript Objects
An object stores related facts under names.
Each fact has a key and a value.
Think of a sticker book. Each sticker has a label and a picture.
1
Make an object
2
Read values
3
Change values
4
Add and remove keys
5
Objects inside objects
Create an object
Use curly braces { } with key value pairs.
javascript
Dot notation
Write objectName.key to read a value.
This is the everyday way.
javascript
Bracket notation
Use brackets when the key is in a string variable.
Also useful for unusual key names.
javascript
Change and add
Assign to a key to change it.
Assign to a new key to add it.
javascript
Remove a key
Use delete to remove a property.
javascript
Nested objects
Objects can hold other objects.
Drill in with more dots.
javascript
Tip: Use objects when facts belong together. A player name and score make a good pair.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.