-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.html
80 lines (63 loc) · 1.96 KB
/
quiz.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz</title>
<link rel="stylesheet" href="./quiz.css">
</head>
<body>
<h4>What's the output?</h4>
<pre>
<span class="blue">var</span> a = 1, b = 2, c = 3;
a = b = c;
console.<span class="violet">log</span>(a,b,c);
</pre>
<ol>
<li><code>1,2,3</code></li>
<li><code>1,1,1</code></li>
<li><code>4,4,4</code></li>
<li><code>TypeError</code></li>
</ol>
<details>
<summary>
Answer
</summary>
<p>3. 4,4,4 </p>
<p>Explanation: assignment operator i.e. <b class="pink">=</b> has right to left precedence.</p>
</details>
<hr />
<h4>What's the output?</h4>
<pre>
function compareMembers(person1, person2 = person) {
if (person1 !== person2) {
console.log('Not the same!');
} else {
console.log('They are the same!');
}
}
const person = { name: 'Lydia' };
compareMembers(person);
</pre>
<ol>
<li>Not the same!</li>
<li>They are the same!</li>
<li>ReferenceError</li>
<li>SyntaxError</li>
</ol>
<details>
<summary>
Answer
</summary>
<p>Answer: B</p>
<p>
Objects are passed by reference. When we check objects for strict equality (===), we're comparing their
references.
We set the default value for person2 equal to the person object, and passed the person object as the value
for person1.
This means that both values have a reference to the same spot in memory, thus they are equal.
The code block in the else statement gets run, and They are the same! gets logged.</p>
</details>
<hr />
</body>
</html>