Hi my name is India Irish. I'm a master's student in the human-centered design and engineering program
at the University of Washington.
I'm all about making people feel comfortable in their environment,
and that's what computer science does.
It's not just guys hanging out in a dungeon coding! That's not what I'm doing.
When lists were first introduced, we used an example list of contacts, represented by a string.
A more useful list stores a lot more information, like last name, email, phone number, and birthday.
To make a contact app, with tools you have now, you may be inclined to make separate lists of each property
that a contact can have, like this:
Where the same number index in each array, corresponds to the same contact.
This is possible, but it's a lot to keep in sync for any operation.
If you want to delete anyone's contact info, you will have to perform 5 different delete operations,
one on each array.
Instead, it's ideal to keep all information related to a single person together in one place.
javaScript can do this by using an Object: a group of related properties with assigned values.
In this example, each object is a contact with related properties,
like first name, last name, email, phone number and birthday.
You can see each property has a corresponding value.
Anything that has a group of related properties can be modeled as an object in code.
For example, apps like Instagram store a bunch of related properties about a single photo, as an object.
Let's create a single photo object, that just stores values for these properties.
First, create a new variable, and assign it an empty object. as represented by a pair of curly braces.
At this point, the photo is an object, but it doesn't hold any data.
To add properties to your object, you can use that notation, where the name of the object
and the properties are connected with a dot.
We can use this notation to create and assign new properties in our object,
much like we would assign values to a variable.
Once we've added properties, we can display its contents using console.log.
Notice when the object is printed out, all at once, each property is paired with its corresponding value.
Lets go back to our contact example from the beginning.
Since we're trying to build the contact list of multiple people each with related properties,
we can make a list of contact objects.
Here we're making two contact objects. Both have the same related properties: name and phone number.
We can then put them, and any future friends, in a contact list.
To access individual objects in our lists, we can use bracket notation.
Here, we're displaying that object stored at Index 1.
If we want to access individual properties of that object,
we can combine bracket notation and dot notation.
Here we are displaying only the name of the contact.
As we start creating apps that store and process greater amount of data,
Objects will be increasingly important tools for keeping the data organized,
and making relationships within the data clear.
Fortunately, we can intuitive names to create and access properties,
to keep our code understandable.