forked from imyagnesh/ReactTraining_29_10_20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcersise.txt
49 lines (37 loc) · 999 Bytes
/
excersise.txt
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
1. With the following code blocks, can you say what will happen in each of these instances?
// what breaks below?
const c1 = 1;
c1 = 3;
// Or updating a string…
const c2 = "hello";
c2 += " world!";
// Or reassigning an object…
const c3 = {};
c3.name = "Geoff";
c3.someValue = "Sausage";
c3 = {};
2. What will be the output for this hoisting example.
var n = 1;
function print() {
console.log("print():1:",n);
var n = 2;
n++;
console.log("print():2:",n);
}
console.log("inline 1: ", n);
print();
console.log("inline 2: ", n);
3. What is the output of folowing block scope
let callbacks = []
for (let i = 0; i <= 2; i++) {
callbacks[i] = function () { return i * 2 }
}
// note the var declaration of the loop iterator
for (var j = callbacks.length; j < 5; j++) {
callbacks[j] = function () { return j * 2 }
}
console.log( callbacks[0]() );
console.log( callbacks[1]() );
console.log( callbacks[2]() );
console.log( callbacks[3]() );
console.log( callbacks[4]() );