We have an object subjects
in the editor.
If we try to add the value "Mathematics"
to the key 104
using the dot operator
it gives an error.
This is because,
the name of the key is not
a proper variable name.
Now, to add the value of this property,
we must use the bracket notation.
In the example given above,
we were able to add
the value "Computer"
to
the 104
key in the object,
because we used the bracket notation.
Similarly, in subjects[21 * 5] = "Mathematics"
,
the expression 21 * 5
evaluates to 105
and hence
"Mathematics"
was assigned to
the property 105
of subjects
.
The dot notation should
only be used if the key
that we are intending to add
or update in the object,
has a valid variable name.