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 JavaScript Objects!
      
    
You have completed JavaScript Objects!
Preview
    
      
  Create an object literal containing various pieces of information about a person.
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
                      Let's create an object literal
to hold various pieces
                      0:00
                    
                    
                      of information about a person.
                      0:03
                    
                    
                      To follow along,
launch the workspace with this video or
                      0:05
                    
                    
                      download the project files and
use your preferred text editor.
                      0:08
                    
                    
                      Open the file object.js.
                      0:11
                    
                    
                      This file is already linked to index.html.
                      0:13
                    
                    
                      First, declare a variable named person,
and assign it a set of curly braces.
                      0:17
                    
                    
                      These two curly braces
represent the object.
                      0:23
                    
                    
                      Now we'll add several property
value pairs to the object.
                      0:27
                    
                    
                      Let's start with the person's name.
                      0:30
                    
                    
                      I'll indent this line, type the property
name, a colon, and the value.
                      0:32
                    
                    
                      Now this person object has a name property
that's assigned the string value, Edward.
                      0:39
                    
                    
                      I'll add another property by
typing a comma, and on a new line,
                      0:46
                    
                    
                      write another property name, city, and
set its value to the string, New York.
                      0:51
                    
                    
                      I've used two string values but you can
use any type of value, like a number or
                      0:59
                    
                    
                      a Boolean.
                      1:03
                    
                    
                      For example, I'll define an age
property and assign it the number 37.
                      1:04
                    
                    
                      Then define a property named isStudent and
assign it the value true.
                      1:10
                    
                    
                      You can also set the value of
an object's property to an array.
                      1:16
                    
                    
                      For instance,
I'll define a new property named skills,
                      1:19
                    
                    
                      and set its value to an array,
                      1:24
                    
                    
                      holding the strings,
JavaScript, HTML and CSS.
                      1:27
                    
                    
                      You can even set the value of
an object's property to a function.
                      1:36
                    
                    
                      You won't be doing that in this course,
but
                      1:39
                    
                    
                      you'll learn about it in a later course.
                      1:41
                    
                    
                      Great, you've created a JavaScript object,
but how do you start using it?
                      1:43
                    
                    
                      I'll teach you how in the next video.
                      1:47
                    
              
        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