#100DaysOfWeb in Python Transcripts
Chapter: Days 25-28: JavaScript Introduction
Lecture: Objects
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
In this video, we will look at objects. They are fundamental building block in JavaScript. Like Python, everything in JavaScript is an object.
0:16
You can say person is Bob. You can method on that object. As a data type and at the most basic level objects can be seen as dictionaries in Python
0:34
and they can in find one using an object literal. If you're familiar with the platform you know that our exercises are called bytes.
0:43
Let's define a byte. A nice thing is that in JavaScript you can access the properties with a dot notation
1:03
but also like a dictionary in Python. Now objects in JavaScript are way more than just dictionaries. They're fully fledged classes under the hood
1:16
so we can also add methods. For example, if we will do something like the Dunder STR in Python you can do that straight on the object.
1:29
And I forgot to mention in the last lesson that anonymous functions are defined like this. Now I'm just starting to print the info of the object
1:36
to the console and to actually access the properties I need to use this, a bit like self in Python. So then I can call that method
1:56
and I get a nice output. So the recap, like Python and JavaScript almost everything is an object. You can define a variable
2:06
and we can call methods on that object. All JavaScript objects inherit properties and methods from a prototype.
2:17
Now a prototypes are beyond of this beginner lesson but I encourage you to look into it further because it supports powerful object-oriented
2:24
program features. To create a simple object we can use an object literal which seems like a dictionary in Python.
2:37
We can access the attributes or properties by the dolt notation or putting the keys in square brackets. We can add methods to our objects
2:49
using the anonymous function notation and here it just bounced the object information to the console and to reference object attributes
2:58
I need to this keyword which is similar to the self keyword in Python classes. Here I call the method and again an output. To inspect objects
3:17
you can use console lock and when you click on the arrow you get a nice representation of the object. You can also use Jason string a pie
3:25
to serialize it to a string. One important notice that objects are copied by reference by default so I would assign byte to a new variable
3:35
called by two and I changed one of their properties that change is reflected in both objects. Some something to keep in mind.
3:41
This concludes the basic JavaScript construct of day one and tomorrow on day two I got four exercises lined up to make you practice the materials
3:50
that you've learned so far. See you tomorrow.