Recall & Review
beginner
What are the two main ways to access properties of a JavaScript object?
You can access properties using dot notation (e.g.,
obj.property) or bracket notation (e.g., obj['property']).Click to reveal answer
beginner
How do you access a property with a name stored in a variable?
Use bracket notation with the variable inside the brackets, like
obj[varName]. Dot notation won't work because it expects a literal property name.Click to reveal answer
beginner
What happens if you try to access a property that does not exist on an object?
JavaScript returns
undefined if the property is not found on the object.Click to reveal answer
intermediate
Can you use bracket notation to access properties with spaces or special characters in their names?
Yes, bracket notation allows accessing properties with spaces or special characters, like
obj['property name'].Click to reveal answer
intermediate
Why might you choose bracket notation over dot notation?
Bracket notation is useful when property names are dynamic, contain spaces, special characters, or are numbers. Dot notation only works with valid identifier names.
Click to reveal answer
Which syntax correctly accesses the property 'name' of an object 'person'?
✗ Incorrect
Both dot notation (person.name) and bracket notation (person['name']) correctly access the 'name' property.
How do you access a property when the property name is stored in a variable 'key'?
✗ Incorrect
Bracket notation with the variable (object[key]) accesses the property named by the variable's value.
What is the result of accessing a non-existing property on an object?
✗ Incorrect
Accessing a property that does not exist returns undefined in JavaScript.
Which notation allows accessing properties with spaces in their names?
✗ Incorrect
Bracket notation allows accessing properties with spaces or special characters, e.g., obj['property name'].
Why might dot notation fail to access some properties?
✗ Incorrect
Dot notation only works with valid identifier names; it fails if the property name is a number, contains spaces/special characters, or is dynamic.
Explain how to access object properties in JavaScript using both dot and bracket notation. When would you use each?
Think about when property names are fixed vs dynamic or unusual.
You got /4 concepts.
What happens if you try to access a property that does not exist on an object? How can you safely check if a property exists?
Consider how JavaScript handles missing properties and how to avoid errors.
You got /2 concepts.