- Object used to store multiple values in single container
- Object is a physical Entity
- It contains in formations,properties and key values
- To differentiate object and property we can use . operator
- Also object contains State and behaviour
- Object contains another object in nested way
(e.g)
const bike={
Brand:"Yamaha Rx 100",
Colour : "Black",
price:1,00000
}
console.log(Bike.price);
Output:1,00000
Explanation
- In this type bike is a object,Brand ,colour ,price are keys for object and Yamaha Rx 100,Black,1,00000 are values.
- To print a bike price declare function and call price
- This print a bike's price
NESTED OBJECT:
const Samsung={
mobile: "S 23 ultra",
price: 1,00000,
colour:"black",
camera:{
rear:{
mp:"50 mp"
}
front:{
mp:"22 mp"
}
},
checking camera mp.function(){
console.log(samsung.camera.rear);
}
};
OUTPUT:50 mp
- This is how nested objects works and execute
Adding a value in object
let student={
name:"Akash",
age:22,
weight:"62 kilogram"
};
student.age=23;
console.log(student.age);
OUTPUT:23
Deleting a Value in object
let student={
name:"Akash",
age:22,
weight:"62 kilogram"
};
delete student.weight;
console.log(student);
OUTPUT:
{name:"Akash",age:22}
Top comments (0)