Javascript
JavaScript Fundamentals -- Objects in JavaScript

Exercise 1 Review

PRO
Outline

Here's one possible solution to the exercise:

'use strict';

// 1. Create a new object called person, with a firstName key and a lastName key
// Put your first and last name as values to those keys
const person = {
  firstName: 'Preston',
  lastName: 'Lamb'
};

// 2. Log the firstName key using dot notation
console.log(person.firstName);
// 3. Log the lastName key using bracket notation
console.log(person['lastName']);
// 4. Freeze the object you created above
Object.freeze(person);

// 5. Try and change an attribute on the object. If you don't see the expected behavior, make the necessary fix so that the freeze method works.
person.middleInitial = 'J';

You can review the answers to this exercise here on StackBlitz.

Click here to read more about objects in JavaScript.

 

I finished! On to the next chapter