-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
302 lines (297 loc) · 12 KB
/
index.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" type="images/x-ico" href="https://cdn.iconscout.com/icon/free/png-256/javascript-23-1174949.png" />
<title>Weird Behavior of JS</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
body {
background-color: white;
text-align: justify;
}
.img {
height: 300px !important;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<div class="row mt-3">
<div class="col-md-12">
<h1># The Weird Parts of JavaScript</h1>
<img src="https://miro.medium.com/max/6300/1*FsqitFvksKYy8Lu3jCQR9w.png" class="img img-thumbnail mt-4">
</div>
<div class="col-md-12 mt-5 text-justify">
<p>We all know that JavaScript is quite a funny language with tricky parts. Some of them can quickly turn our
everyday job into hell, and some of them can make us laugh out loud. Here, I am going to make collection of
some javascript weird problems & questions. Which you even can't think about.</p>
</div>
<div class="col-md-12 mt-5">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Sr. No.</th>
<th>Question</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.</td>
<td>
<div class="row text-left">
<div class="col-md-4">console.log([ ] === [ ]);</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">console.log([ ] == [ ]);</div>
<div class="col-md-12 text-right">returns <b>FALSE</b>.</div>
</div>
</td>
</tr>
<tr>
<td>2.</td>
<td>
<div class="row text-left">
<div class="col-md-12">
let a = {'name' : 'Shivam'}<br />
let b = a;<br />
b.name = 'Sam';<br />
console.log(a.name);
</div>
<div class="col-md-12 text-right">Guess Output : <b>Sam or Shivam?</b></div>
</div>
</td>
</tr>
<tr>
<td>3. </td>
<td>
<div class="row text-left">
<div class="col-md-4">typeof <b>undefined</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>undefined</b>);</div>
<div class="col-md-12 text-right">Output : <b>undefined</b>.</div>
</div>
</td>
</tr>
<tr>
<td>4. </td>
<td>
<div class="row text-left">
<div class="col-md-4">typeof <b>null</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>null</b>);</div>
<div class="col-md-12 text-right">Output : <b>object</b>.</div>
</div>
</td>
</tr>
<tr>
<td>5. </td>
<td>
<div class="row text-left">
<div class="col-md-4">typeof <b>String</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>String</b>);</div>
<hr />
<div class="col-md-4">typeof <b>Number</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>Number</b>);</div>
<hr />
<div class="col-md-4">typeof <b>Object</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>Object</b>);</div>
<hr />
<div class="col-md-4">typeof <b>Function</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>Function</b>);</div>
<hr />
<div class="col-md-4">typeof <b>Boolean</b>;</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">typeof(<b>Boolean</b>);</div>
<hr />
<div class="col-md-12 text-right">Output : <b>Function</b>.</div>
</div>
</td>
</tr>
<tr>
<td>6. </td>
<td>
<div class="row text-left">
<div class="col-md-6"> ['1', '7', '11'].map(parseInt); </div>
<div class="col-md-6 text-right">Can you guess the <b>Output</b>?</div>
</div>
</td>
</tr>
<tr>
<td>7. </td>
<td>
<div class="row text-left">
<div class="col-md-6">console.log(0.2 + 0.1 === 0.3);</div>
<div class="col-md-6 text-right">Can you guess the <b>Output</b>?</div>
</div>
</td>
</tr>
<tr>
<td>8. </td>
<td>
<div class="row text-left">
<div class="col-md-6">console.log(Math.max() > Math.min());</div>
<div class="col-md-6 text-right">Output : <b>True</b> or <b>False</b>?</div>
</div>
</td>
</tr>
<tr>
<td>9. </td>
<td>
<div class="row text-left">
<div class="col-md-6">console.log(018 - 017);</div>
<div class="col-md-6 text-right">Can you guess the <b>Output</b>?</div>
</div>
</td>
</tr>
<tr>
<td>10. </td>
<td>
<div class="row text-left">
<div class="col-md-6">Have you ever hear about the <b>"Bang Bang Operator" (!!)</b> in JS?</div>
<div class="col-md-6 text-right">
<a href="https://medium.com/better-programming/javascript-bang-bang-i-shot-you-down-use-of-double-bangs-in-javascript-7c9d94446054"
target="_blank">Answer</a>
</div>
</div>
</td>
</tr>
<tr>
<td>11. </td>
<td>
<div class="row text-left">
<div class="col-md-12"><b><i>Write a JS function to take any number of Arguments.</b></i></div>
<div class="col-md-12 mt-3">
function add(...args) {<br />
let result = 0;<br />
for (let arg of args)<br />
result += arg;<br />
console.log(result);<br />
}<br />
add(1) // returns 1<br />
add(1,2) // returns 3<br />
add(1, 2, 3, 4, 5) // returns 15<br />
</div>
</div>
</td>
</tr>
<tr>
<td>12. </td>
<td>
<div class="row text-left">
<div class="col-md-12">What are Spread Operators?</div>
</div>
</td>
</tr>
<tr>
<td>13. </td>
<td>
<div class="row">
<div class="col-md-4">Does JS have types?</div>
<div class="col-md-3">OR</div>
<div class="col-md-5">Data Types in Javascript</div>
<div class="col-md-10 offset-md-1 mt-3">
Some may argue that JS is <b>Untyped</b> or that it shouldn’t call its type system types. It doesn’t
require you to declare a type when making a variable like in some other strongly typed languages i.e
int x = 10.<br />But, I would argue that JS does have types.
</div>
<div class="text-secondary mt-3 mb-2 col-md-12"><i>JS is both <b>dynamically typed</b> and <b>weakly
typed</b>.</i></div>
<div class="col-md-12">let's discuss more about Static typed & Dynamic typed language.</div>
</div>
</td>
</tr>
<tr>
<td>14. </td>
<td>
<div class="row">
<div class="col-md-12">Statically Typed ~</div>
<div class="col-md-10 offset-md-1">
JS is not statically typed unless you’re using a language, tool such as Typescript or Flow that
compiles to JS code. Statically typed means the type is enforced and won’t change so easily. All
variables must be declared with a type. <br />
int x = 5; <br />
string y = 'abc';
</div>
</div>
</td>
</tr>
<tr>
<td>15. </td>
<td>
<div class="row">
<div class="col-md-12">Dynamically Typed ~</div>
<div class="col-md-10 offset-md-1">
Dynamically typed languages infer variable types at runtime. This means once your code is run the
compiler/interpreter will see your variable and its value then decide what type it is. The type is
still enforced here, it just decides what the type is. <br />
var a = 1 // int<br />
var b = 'test' // string
</div>
</div>
</td>
</tr>
<tr>
<td>16. </td>
<td>
<div class="row">
<div class="col-md-12">Weakly Typed ~</div>
<div class="col-md-10 offset-md-1">
Weakly typed languages allow types to be inferred as another type. For example,<br />
<span class="text-secondary">console.log(1 + '2'); // '12'</span><br />
In JS, it sees you’re trying to add a number with a string — an invalid operation — so it coerces
your number
into a string and results in the string ‘12’.
</div>
</div>
</td>
</tr>
<tr>
<td>17. </td>
<td>
<div class="row">
<div class="col-md-12">Primitives Data Types in JS.</div>
<div class="col-md-10 offset-md-1">
There are six types, considered to be Primitives.
A primitive is not an object and has no methods of its own. All primitives are immutable.<br/>
<span class="text-secondary">Boolean — true or false<br/>
Null — no value<br/>
Undefined — a declared variable but hasn’t been given a value<br/>
Number — integers, floats, etc<br/>
String — an array of characters i.e words<br/>
Symbol — a unique value that's not equal to any other value<br/></span>
Everything else is an Object type.<br/>
</div>
</div>
</td>
</tr>
<tr>
<td>18. </td>
<td></td>
</tr>
<tr>
<td>19. </td>
<td></td>
</tr>
<tr>
<td>20. </td>
<td></td>
</tr>
<tr>
<td>21. </td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>