Objects in programming languages (JavaScript) - 19

- Andrés Cruz

En español
Objects in programming languages (JavaScript) - 19

In a real world a car is an object, a table is an object; and in JavaScript we have ways to represent these kinds of structures.

Objects in JavaScript are an approach to the classes that are supported by other programming languages such as PHP or Python but much simpler.

If we analyze an object in the real world, such as a car, we will see that it has common characteristics that allow us to discriminate by different types; for example.

A car has a brand, it has a model, it has weight and it has a color; to name its most basic elements. We in JavaScript can simulate this behavior using objects.

To create an object in JavaScript we can do it as follows

var car = {brand:"Fiat", model: 5000, color: "White"}

As you can see, it is a very simple structure and it seems that we have a variable that contains variables; but if you look at the assignment we do internally it changes, we no longer use equals but rather colons, because now we are working with objects and not with variables.

So starting from the previous object, to access, for example, the name of the car


As you can see, we simply access the object called car and it would be the attribute, which is how each of the variables or pseudovariables that are contained within the car are now known; Otherwise everything remains exactly the same, depending on the type of data of these attributes we can do some operations or others, such as adding, subtracting, etc.

We can also access each of its attributes to update a value:

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.