{}
is object literal syntax.
let say
const circle = {};
Above circle is returning an object.
Object in Javascript is essentially collection of key-value pair.
const circle = {
radius: 1,
location: {
x: 1,
y: 1
},
draw: function() {
console.log('draw');
}
};
This circle object have 3 members: radius
, location
and draw
If a member is
- function then it refers as
method()
, sodraw
is method. - Other members are called as
properties
.
Now, you can access the method or property using the .
notation like:
circle.draw()
and it will output, draw in console.
So, this is most commonly used method of defining an object.
You, can also define an object using factories and constructors.
How factories and constructors works and what is the other way of accessing the object will be explained in next blog.
Follow @msabir to keep yourself updated.
Cheers.
Stay tune for next update!!