Objects – Creation and Access, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Objects – Creation and Access in one minute
What students need to know
Bracket notation requires the key as a quoted string. The colon divides each key from its corresponding value.
Curly braces hold the key-value pairs of an object. Dot notation accesses a value using its key directly.
Mistakes students make
- Objects use curly braces {}, not round brackets ().
- Missing the colon between the key and its value.
- Dot notation uses a period, not a #, before the key.
- A key used in bracket notation needs quotes around it.
PREVIOUS · MODULE 31String Search Methods
YOU ARE HERE · MODULE 32Objects – Creation and Access
NEXT · MODULE 33Objects – Methods (keys, values, entries)
What students will learn in this module
Every question in Module 32
Quick questions
- Does {} create an object holding key-value pairs?ANoBYes
- Does object.name access the value stored at key name?ANoBYes
- Does bracket notation require quotes around the key?AYesBNo
- Is () used to create an object in JavaScript?ANoBYes
- Are keys and values separated by a colon in an object?AYesBNo
Key terms
Students type the meaning of:
{}
Match the pairs
{name: "Sam", age: 12}Match it to what it doesperson.nameMatch it to what it doesAccesses a value using a key wrapped in quotesMatch it to what it doesSeparates a key from its value inside an objectMatch it to what it doeslet a = (name: "Sam");Match it to what it doesconsole.log(person[name]);Match it to what it doesFill in the blanks
let person = _name: "Sam"};
Hint: Type the symbol that opens an object.
console.log(person_name);
Hint: Type the symbol used for dot notation access.
console.log(person_"name"]);
Hint: Type the symbol that opens a bracket notation access.
let car = {color_ "red"};Hint: Type the symbol that separates a key from its value.
let dog = {name: "Rex"_;Hint: Type the symbol that closes an object.
Spot the error
Question 1
Alet a = (name: "Sam");Bconsole.log(a.name);Clet b = {age: 12};
Question 2
Alet c = {name "Amy"};Bconsole.log(c.name);Clet d = {age: 9};
Question 3
Alet e = {name: "Bo"};Bconsole.log(e#name);Clet f = {age: 8};
Question 4
Alet g = {name: "Al"};Bconsole.log(g[name]);Clet h = {age: 7};
Question 5
Alet i = {name: "Zo"};Bconsole.log(i.name);Clet j = {age: 6;
