DEV Community

R.Shobika CSE
R.Shobika CSE

Posted on

OBJECT PART - 1

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,
}
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

It will print all the values in the mobile . If you want price only means.

console.log(mobile.price);
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

output:
8

Object - function (Method)

const mobile={
name : "redme",
price : 20000,
storage: {
ram:8,
rom:256,
},
browser:function(){
console.log("5g speed");
}
}
mobile.browser();
Enter fullscreen mode Exit fullscreen mode

output:
5g speed

Top comments (0)