Creating and reading
JavaScript · Unit 7: Objects
- Full plan
- JavaScript
- 10 exercises
An object stores data by name. It goes inside braces {} and each piece of data is a property: the name, a colon and the value, with commas between them.
If it doesn't fit on one line, you write one property per line.
const ava = {
name: "Ava",
age: 17,
};
console.log(ava);Prints
{ name: 'Ava', age: 17 }The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Multiple choice
Which of these lines creates an object with two properties?
2. Predict the output
What does this code print?
3. Complete the code
Complete it to print Mia's age.
4. Predict the output
What does this code print?
5. Find the bug
This program should print the price of the item asked for, 5. Which line has the error?
6. Predict the output
What does this code print?
7. Predict the output
Look closely at the capital letter. What does it print?
8. Put the lines in order
Order the lines to print how many hours the movie lasts, with one decimal.
9. Predict the output
What does this code print?
10. Find the case that fails
greet(p)should return"Hi, "plus the person's name, or"Hi, friend"if the object has noname. Which call makes it fail?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.