Reading a book I found the following:
Once the object properties are created, they can be accessed in two ways:
obj.nombre = "Simon";
var nombre = obj.nombre;
Y...
obj["nombre"] = "Simon";
var nombre = obj["nombre"];
These are semantically equivalent. The second method has the advantage that the property name is passed as a string, which means that it can be computed at runtime although using this method prevents some JavaScript engine optimizations from being applied.
What do you mean by 'calculated at runtime' and the other question is the relationship with the javascript engine?
I think that these are two questions in one, and that the second one could even be somewhat broad, but very interesting if you put it well, but I repeat, it would be a separate topic.
I will limit myself to answering your first question.
In the code example that MDN uses in the Working with objects section , you can easily see the cases in which it should be used
[]
to define the properties of objects.Suppose an object that would have, among its properties, a random value. In that case, using square brackets you can easily assign that value:
As you can see, the fourth property of the object is correctly generated dynamically at runtime.
However, this is not possible.
Objeto.propiedad
. As you can see in the code, a property is created whose name is fixed, not a property with the value of the variablealeatorio
obtained in Random.Fecha de creación
pain of error." "
as the property name of an object.Object
instead of the value contained within it.