Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Everything in JavaScript is an object or can be treated like one. Learn about familiar JavaScript objects to get a deeper understanding of why objects are useful.
JavaScript Data Structures
Interested in learning more about objects and other data structures in JavaScript? Check out the following documentation:
-
0:00
Hey, welcome back.
-
0:01
In the last video, we started conceptualizing what an object is and
-
0:05
how objects can be used in our code.
-
0:08
In this video, we're going to build on that by talking about objects
-
0:11
in JavaScript that you're already familiar with.
-
0:14
Most everything you encounter when programming in JavaScript is an object or
-
0:18
can be treated like an object.
-
0:20
For example, in your course progression, you have probably heard of or
-
0:24
encountered the DOM, or the Document Object Model.
-
0:27
That's just the object that represents the HTML document
-
0:30
your JavaScript interacts with.
-
0:32
DOM elements are objects and have properties and methods.
-
0:35
For example, I can get an element styles with the style property.
-
0:39
I can get the HTML that an element is made of with the innerHTML property.
-
0:44
I can even get an element's parent with the parentNode property, or
-
0:47
its children with the childNodes property.
-
0:49
DOM objects have methods as well, like getElementById or appendChild.
-
0:55
Did you know that arrays are another example of a JavaScript object?
-
0:59
Arrays have properties like length and methods like push, pop, and concat.
-
1:05
What's great about these objects is that they've abstracted away a lot of
-
1:08
the details for you.
-
1:09
In other words, they created an interface that lets you use the object without
-
1:13
having to know what's going on under the hood.
-
1:16
You can use the method, getElementById, over and over without having to know
-
1:21
how that works or rewrite all the code that's underneath it.
-
1:25
As you can see, objects can make it really easy to get up to speed with code basis
-
1:30
you aren't familiar with.
-
1:31
If you design and document your own objects well,
-
1:34
another developer can start working with your code right away.
-
1:38
Objects are everywhere in JavaScript.
-
1:40
You can design your own to model real life objects that you want to use in your code,
-
1:44
or use them as a container to store and access data.
-
1:47
Hopefully you're starting to have a clear understanding of what objects are and
-
1:51
why and how we use them.
-
1:53
If you have any questions about OOJS so far or
-
1:56
you just want to discuss what you've learned.
-
1:58
The Treehouse Community is a really great place to connect with other students and
-
2:02
get or give extra help.
-
2:04
Join me in the next stage to get familiar with some really important terms, and
-
2:08
get your hands dirty as you start learning about the practical application
-
2:11
of objects in your code.
You need to sign up for Treehouse in order to download course files.
Sign up