Check out a free preview of the full Professional JS: Features You Need to Know course

The "Object Management" Lesson is part of the full, Professional JS: Features You Need to Know course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano discusses various tools available in the object class in JavaScript such as object.assign, object.entries, object.values, object.fromEntries, object.hasOwnProperty, and object.is.

Preview
Close

Transcript from the "Object Management" Lesson

[00:00:00]
>> Maximiliano Firtman: Okay, so now talking about object. So object is the object class. We are talking about instances here, not class declaration, but instances. Here I have a list of some tools that we have available that they are available in different versions of ECMAScript. Here you can see that a sign 15 entries 17.

[00:00:22]
So, I have a hasOwn change ratios. I have a lot of examples here. These are just very small changes to the object class tools to use. For example, in this case, object assign will actually copy the values of all the own properties from one or more objects to a target object, so it will copy the properties.

[00:00:47]
Do you know what's an own property, or what's the difference between property and own property?
>> Student: Ones that don't come from the prototype chain?
>> Maximiliano Firtman: Yeah, that's correct. So an own property, it's a property that is defined in that particular object and it's not coming from the prototype chain.

[00:01:05]
That from an OOP perspective, it's like saying that it's not coming from the hierarchy, from the super class, okay? But it's not always a super class in JavaScript, but that's the idea. So in this case, we have a target, we have a source. With b and c and a target, and then you assign that, and now the assign is this one.

[00:01:27]
Now it has a, so now the target, actually the return target because it's a third object, it's assigning a, b, and c. It's just that. Then get entries, actually entries, not entry, entries, will convert all the own properties into a key value array pair. So, for example, this object that you see here, it's converted into an array, it's an array with sub arrays with key value, key value, key value.

[00:02:01]
It's just that. It converts an object into that other format. Values will give an array only with the values, with no keys. Is it useful? There are very specific reasons to do that. And also, you can kind of do something similar with the 14 so you can emulate the, sometimes there's more differences between one or the other, but just that.

[00:02:30]
So then, from entries, object from entries is actually the counterpart of this one of entries. With from entries, you can take this structure, array of sub arrays, an array with an array of key value, and convert that back into an object. It's like serializing an object to arrays and vice versa, something like that.

[00:02:56]
And hasOwn is just a way to know if one object has its property, but it's an own property, and it's not a property coming from the hierarchy or the prototype chain, okay? For example, just string is available on every object. So when you're asking for this object, the object has it to a string, but it's not an own property.

[00:03:21]
So it gives you false. And a, it's an own property. Okay, it's just that. And also from ES6, you have the is that it's actually pretty similar to the triple equals operator, but not 100% the same. So, it has to do with the not so happy none value, not the number, so it has to do with that.

[00:03:54]
Actually, we need to spend like 20 minutes to understand the difference between if and triple equals. I don't think it's worth the time, but have in mind it's there, okay?

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