let FCC_User = {The above code defines an object called
username: 'awesome_coder',
followers: 572,
points: 1741,
completedProjects: 15
};
FCC_User that has four properties, each of which map to a specific value. If we wanted to know the number of followers FCC_User has, we can access that property by writing:
let userData = FCC_User.followers;This is called dot notation. Alternatively, we can also access the property with brackets, like so:
// userData equals 572
let userData = FCC_User['followers']Notice that with bracket notation, we enclosed
// userData equals 572
followers in quotes. This is because the brackets actually allow us to pass a variable in to be evaluated as a property name (hint: keep this in mind for later!). Had we passed followers in without the quotes, the JavaScript engine would have attempted to evaluate it as a variable, and a ReferenceError: followers is not defined would have been thrown.
foods object with three entries. Add three more entries: bananas with a value of 13, grapes with a value of 35, and strawberries with a value of 27.
foods is an object
testString: assert(typeof foods === 'object', 'foods is an object');
- text: The foods object has a key "bananas" with a value of 13
testString: assert(foods.bananas === 13, 'The foods object has a key "bananas" with a value of 13');
- text: The foods object has a key "grapes" with a value of 35
testString: assert(foods.grapes === 35, 'The foods object has a key "grapes" with a value of 35');
- text: The foods object has a key "strawberries" with a value of 27
testString: assert(foods.strawberries === 27, 'The foods object has a key "strawberries" with a value of 27');
- text: The key-value pairs should be set using dot or bracket notation
testString: assert(code.search(/bananas:/) === -1 && code.search(/grapes:/) === -1 && code.search(/strawberries:/) === -1, 'The key-value pairs should be set using dot or bracket notation');
```