-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.js
56 lines (39 loc) · 1.02 KB
/
objects.js
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
//OBJECTS {key : value}
const person = {
name: 'Leonardo',
shirt: 'white'
}
// Acessing values from the person (dot method)
console.log(person.name)
console.log(person.shirt)
//Acessing values from the person (bracket method)
console.log(person['name'])
console.log(person['shirt'])
//accessing the whole object
console.log(person)
//putting a property into object
person["phone"] = "998877655"
console.log(person)
//person2
const person2 = {
name: "Qazi",
shirt: "black"
}
console.log(person2)
console.log(person2.name)
function introducer(name, shirt, assets, liablity) {
const person = {
name: name,
shirt: shirt,
assets : assets,
liablity: liablity,
//creating a method
networth : function () {
return this.assets - this.liablity
}
}
x = `Hi my name is ${person.name} and my shirt color
is ${person.shirt} and my net worth is ${person.networth()}`
return x
}
console.log(introducer("satyam", "green", 1000000, 20000))