-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadme file
More file actions
113 lines (77 loc) · 3.56 KB
/
Readme file
File metadata and controls
113 lines (77 loc) · 3.56 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
102
103
104
105
106
107
108
109
110
111
112
113
Section 1:-
Problem - 1:
When we start the program, the output is:
Console.log (Counter ()) => Output is 1
Console.log (Counter ()) => Output 2 is
Console.log (Counterb ()) => Output is 1
Both counters, counters and counters are independent of each other. As a result of closing, each counter claims that it is our calculator variable, which is called the function every time, so it makes them independent.
Problem - 2:
The code is output:
Hello, undefined! => Printed after 0 seconds
Hello, undefined! => Printed after 1 second
Hello, undefined! => Printed after 2 seconds
To work as expected, we can use "late" instead of "var" because "late" has a range of blocks. SND for each recurrence I was awarded and the value is correctly printed.
Section - 2: -
Part - 1:
In JS, the use of jacks, variable announcements are transferred to the top of the program.
The scope of secrets is a function, and since the value is not yet integrated and variables declared using "var" are raised to the top and returns unhappy.
When we use "late" or "cast" instead of "var" in the program, the variable is still raised at the top, but cannot be used without a statement. This is called a temporary dead zone that provokes an error before the announcement when accessing the variable.
Part 2:
1) In JS, "to" refers to an object that calls a function. Because the function inside Settimeout is not an object, it returns to undefined.
2) The variable solves the problem of "IT" in itself, because it will never change and the user refers to an object.
3) In the arrow functions, the "of this" value is inherited from where they define. So here, in Gumdelayed (), this.Name the user refers to the object correctly.
4) Using arrows
Const Userdelayed = {
Name: "Revan",
Greeting: Function () {
Settimeout (() => {
Console.log (The Highlird of Nightcourt is: $ {this.name}!);
}, 4000);
}
};
userdelayed.greetuser ();
Part - 3:
1) Yes, counters and counters are independent and separate variables. Every time a new number variable is made for closure when it is called Sectuase ().
2))
FUNCTION CREATEGRATEING (greeting) {
Return function (name) {
Return $ {greeting}, $ {name}!;
};
}
Const Sayhello = Createregreeting ("Hello");
Console.log (Sayllo ("World"));
3) 4)
CREATESECRETHOLDER (Secret) function {
return {
Getsecret: Function () {
the return of mystery;
},
Setsecret: Function (Secrecret) {
Secret = therecrecret;
}
};
}
Const Holder = Createsecretholder ("Mysecret");
Console.log (Holder.getsecret ());
Holder.setsecret ("Prosececret");
Console.log (Holder.getsecret ());
Part - 4:
1) In JS, the remaining parameter allows you to accept an indefinite number. Argument as a field. Therefore, if you don't know exactly. The arguments can be used by the rest parameter. If parameters are smaller than arguments, undefined are returned to missing people.
2) Function Function_Name (A, B, C, ... Rest) {
Console.log ("value and is:", a);
Console.log ("Rest is:", rest);
,
FUNCTION_NAME (5, 10, 15);
3) Sumall function (... ANY) {
Return any.reduc ((sum, n) => sum + n, 0);
}
Console.log (Sumall (12, 34, 15));
Console.log (sumall ());
4)
functional processorguments (primary function, ... rest) {
Return of the primary function (... rest);
}
function multiply (a, b) {
return a * b;
}
Console.log (processarguments (Multiply, 123, 445));