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