Member-only story
Object in Javascript with example
- Object in javascript is a kind of container for storing values or you can say it is a kind of variable with multiple values. As we all know that a javascript variable contains a single value which means we can only assign a single value to a javascript variable.
- It holds the values using the name: value pair.
- javascript object is declared with the keyword const.
- parenthesis is used to declare javascript objects.
const object = {name:value,name1:value1,name2:value2};
Below is an example of a javascript object
const boy = {first_name: "Robin",last_name: "Sinha",age:30};
Also, you can write the above object as shown below
const boy = {
first_name: "Robin",
last_name: "Sinha",
age:30};
}
whereas boy is the name of the object
first_name is the property name
Robin is the property value
From the above example, you can see some values inside the object. Those values are known as object properties. These values can be used in the methods if we declare the methods along with the object properties. Also, note that we have to use the first bracket at the time of calling methods using the javascript objects.