Repository navigation
Expand file tree
/
Copy pathSJ_10_Objects.html
More file actions
101 lines (88 loc) · 2.91 KB
/
Copy pathSJ_10_Objects.html
File metadata and controls
101 lines (88 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Objects</title>
</head>
<body>
<script>
let product={
company: 'Levis',
price: '1000',
item_name: 'T-shirt',
'item-material': 'Cotton',
};
console.log(typeof product);
console.log(product);
console.log(product.company);
console.log(product.price);
product.company ='H&M';
console.log(product);
console.log(product['item_name']);
console.log(product['item-material']);
let propertyName='item_name';
console.log(product[propertyName]);
console.log(product.propertyName); //undefined as it is searching as propertyName as key value
delete product.company; //deletes company name
console.log(product);
//nested objects
let material={
company: 'Levis',
itemName: 'Cotton striped t-shirt',
price: 1500,
rating: {
stars: 4.5,
noOfReviews: 87,
},
displayPrice: function(){
console.log(`Price of the product is ₹ ${this.price}`)
}
};
material.displayPrice();
console.log(material);
//Autoboxing
console.log('Hello! This is Sweta Jha'.toUpperCase());
console.log('Hello! This is Sweta Jha'.replace('Sweta', 'Pooja'));
// Object references
let a =5;
let b=a;
console.log(`a= ${a}, b= ${b}`); // 5,5
a=8;
console.log(`a= ${a}, b= ${b}`); // 8,5
let x= {num: 5};
let y=x;
console.log(`x= ${x.num}, y= ${y.num}`); //5,5
x.num=8;
console.log(`x= ${x.num}, y= ${y.num}`); //8,8
let p ={pop:'sweta'};
let q ={pop:'sweta'};
console.log(p==q); //false
console.log(p===q); //false
//object shorthand
let Goods={
brand: 'Levis',
itemName: 'Cotton t-shirt',
amount: 850,
service: 'by Amazon India'
};
//let brand = Goods.company
// is same as
let { service} = Goods;
let { brand, amount } = Goods; //destructure
console.log(service);
console.log(brand,amount);
console.log(amount);
//property shorthand
let cost =1800;
let manufacturingProduct={
manuufacturer: 'Levis',
itemName: 'Cotton striped Top',
cost,
displayCost(){
return ` Rs ${this.cost}`}
};
console.log(manufacturingProduct.displayCost());
</script>
</body>
</html>