OBJECT
In JavaScript object contains a information. it will show as a key value pair it is used for a structured and well design for easy to identify . Object is a Non primitive datatype , Its contain Properties and method
const mobile={
name : "redme",
price : 20000,
storage: 512
}
const mobile1 = {
name : "samsung",
price : 30000.
storage : 216,
}
The Above coding is the Object creation
How to print a object ?
Same patten console.log but here we have to call the value
console.log(mobile);
It will print all the values in the mobile . If you want price only means.
console.log(mobile.price);
we have to use the dot operator .
Nested Object
const mobile={
name : "redme",
price : 20000,
storage: {
ram:8,
rom:256,
}
}
console.log(mobile.storage.ram)
output:
8
Object - function (Method)
const mobile={
name : "redme",
price : 20000,
storage: {
ram:8,
rom:256,
},
browser:function(){
console.log("5g speed");
}
}
mobile.browser();
output:
5g speed
Top comments (0)