DEV Community

Cover image for JavaScript Objects
Zouhair Sahtout
Zouhair Sahtout

Posted on

JavaScript Objects

In JavaScript, an object is a non-primitive, structured data type used to store various keyed collections and more complex entities.

There is many ways of declaring objects, this one called:
The Object Literal Syntax
Image description


There's two different ways of accessing to the properties of an object

Using: dot notation:
console.log(zouhair.firstName);

Using: bracket notation:
console.log(zouhair['lastName']);


Different

The big difference between these two up here, in the "bracket notation" we can put an "expression" - (expression produce a value).
Any time we try access a property on an object does NOT exists we get undefined.

Image description


Adding properties

Adding new properties to the object using both: dot notation and bracket notation

Image description


Operator precedence

In terms of "operator precedence":
. and [] : they have the same precedence which is 17,
and both from left-to-right

Image description

Top comments (0)