-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
74 lines (61 loc) · 1.72 KB
/
random.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function changeAgeAndName(person) {
person.age = 25;
// person.name = "adarsh"
person = {
age: 50,
name: "bhemu"
}
return person;
}
let person1 = {
name: "aditya",
age: 30
}
const person2 = changeAgeAndName(person1);
// console.log("person1", person1)
// console.log("person2", person2)
// convert given john object to ES6 standard
var john = {
name: 'John Doe',
balance: 1500,
deduct: function(amount) {
this.balance = this.balance - amount;
return this.name + " has a balance of " + this.balance;
}
}
// console.log("john", john.deduct(200));
const johnES6 = {
name: 'John Doe',
balance: 1500,
deduct: () => {
return function(amount) {
this.balance = this.balance - amount;
return this.name + " has a balance of " + this.balance;
}
}
}
// console.log("johnES6", johnES6.deduct().call(john, 200)); // call function calls a function with the given this and set of arguments
const john2 = {
name: 'John Doe',
balance: 1500,
deduct(amount) {
return new Promise((resolve, reject) => {
this.balance = this.balance - amount;
setTimeout(() => {
resolve(`${this.name} has a balance of ${this.balance}`);
}, 2000);
}).then(resp => resp)
}
}
// john2.deduct.call(john2, 200).then(resp =>console.log(resp))
//tagged template
function greet(text) {
console.log("text", text)
return "Hello";
}
// console.log(greet `Hi`) //it is similar to greet(["Hi"])
// console.log(greet `${"Hi"}${"Biro"}`) //it is similar to greet([], "Hi", "Biro")
function lengthOfArgs() {
return arguments.length;
}
// console.log(lengthOfArgs(1, 2, 3, 4, 5));