This content originally appeared on DEV Community and was authored by DEV Community
{}
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 member 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.
This content originally appeared on DEV Community and was authored by DEV Community
DEV Community | Sciencx (2022-03-07T05:08:58+00:00) {} – Object Literals in Javascript. Retrieved from https://www.scien.cx/2022/03/07/object-literals-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.