0
0
Javascriptprogramming~5 mins

Accessing object properties in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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'?
Aperson.name
Bperson->name
Cperson['name']
DBoth A and C
How do you access a property when the property name is stored in a variable 'key'?
Aobject[key]
Bobject.key
Cobject.'key'
Dobject->key
What is the result of accessing a non-existing property on an object?
Aundefined
Bnull
C0
DError
Which notation allows accessing properties with spaces in their names?
ADot notation
BBoth dot and bracket notation
CBracket notation
DNone
Why might dot notation fail to access some properties?
AIf the property name is a number
BAll of the above
CIf the property name is stored in a variable
DIf the property name contains spaces or special characters
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.