Check out a free preview of the full The Hard Parts of Object Oriented JavaScript course

The "Object dot Notations" Lesson is part of the full, The Hard Parts of Object Oriented JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

The basic way to assign data to an existing object is introduced.


Transcript from the "Object dot Notations" Lesson

>> Will Sentance: What is another way that we might go about creating objects? Well, the first one we saw there was just what's called an object literal. Let's just remind ourselves that we can also create an object, empty object, and then assign its properties with dot notation. We're gonna do this again, and again, and again today.

Just remember, remind ourselves, we can assign properties to an object literal, to an object, using dot notation in JavaScript. Let's have a look at it, let's start diagramming this out. Line one here Michael, what are we doing, we're gonna actually verbalize our code as we go, we're gonna map it out on the whiteboard.

So tell me what we're doing here in line one, Michael.
>> Michael: So we're creating a const called user two in memory.
>> Will Sentance: In memory, so I'm gonna mark up this area of my whiteboard to be, with my brand new pens, to be our memory. And the first thing, spot on, Michael, what is User2, which is a const, a constant, that means we can't switch the whole object out.

We can change properties, but we can't get rid of the whole object from memory, because it's a constant. It's got the same position in memory. It's assigned what, Michael?
>> Michael: An object literal.
>> Will Sentance: Spot on, an empty object to which we're then gonna stick some properties. Talk me through the property assignment, Michael.

>> Michael: First one, we're gonna create a name property.
>> Will Sentance: With what value?
>> Michael: With a Julia.
>> Will Sentance: And?
>> Michael: And then score with a value of 5.
>> Will Sentance: Fantastic, and then we're gonna attach that pertinent functionality, that relevant functionality that we wanna have available on the object. Beautiful, there it is.

It's the increment function. Can we now do our user2.increment? Don't panic! There's our increment function. We absolutely can.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now