Practice: Exploring Objects Using JavaScript

In this section, you'll use JavaScript to create a "person" object. The code can be run in any browser and uses the Developer Console. This practice exercise does not count towards your grade. It is just for practice!

Here are the contents of the file:

<!DOCTYPE html>
<html>
<head>
<meta charset ="utf-8">
<title>Object-oriented JavaScript example</title>
</head>
<body>

<p>This example requires you to enter commands in your browser's JavaScript console
(see What are browser developer tools for more information).</p>

</body>

<script>

</script>
</html>

There is another way to access object properties – using bracket notation. Instead of using these:

person.age
person.name.first

You can use

person['age']
person['name']['first']

This looks very similar to how you access the items in an array, and it is basically the same thing – instead of using an index number to select an item, you are using the name associated with each member's value. It is no wonder that objects are sometimes called associative arrays – they map strings to values in the same way that arrays map numbers to values.