1
1
// 1) What is the output of 10+20+"30" in JavaScript?
2
2
//Ans: 3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).
3
-
3
+
4
4
// 2) What is the output of "10"+20+30 in JavaScript?
5
5
// Ans: 102030 because after a string all the + will be treated as string concatenation operator (not binary +).
6
6
7
7
// 3) Output?
8
8
// Syncronous
9
9
[ 1 , 2 , 3 , 4 ] . forEach ( ( i ) => {
10
- console . log ( i )
11
- } )
10
+ console . log ( i ) ;
11
+ } ) ;
12
12
13
13
// Asynchronous
14
14
function asyncForEach ( array , cb ) {
15
15
array . forEach ( ( ) => {
16
16
setTimeout ( cb , 0 ) ;
17
- } )
17
+ } ) ;
18
18
}
19
19
20
20
asyncForEach ( [ 1 , 2 , 3 , 4 ] , ( i ) => {
21
21
console . log ( i ) ;
22
- } )
23
-
22
+ } ) ;
24
23
25
24
// 4) Output? And explain (hint: Octal)
26
- console . log ( 016 )
25
+ console . log ( 016 ) ;
27
26
28
- console . log ( 017 )
27
+ console . log ( 017 ) ;
29
28
30
- console . log ( 026 )
29
+ console . log ( 026 ) ;
31
30
32
- console . log ( 027 )
31
+ console . log ( 027 ) ;
33
32
34
33
// 5) Output?
35
- console . log ( [ ...'Hello' ] ) ;
34
+ console . log ( [ ..."Hello" ] ) ;
35
+
36
+ // OUTPUT
37
+ function sum ( a , b ) {
38
+ a = 10 ;
39
+ return [ a + b , arguments [ 0 ] + arguments [ 1 ] ] ;
40
+ }
41
+
42
+ // in "use strict" => [12, 3]
43
+ // in normal mood => [12, 12]
44
+ console . log ( sum ( 1 , 2 ) ) ;
45
+
46
+ // Event Propagation
47
+ // event.currentTaget.tagName
48
+ // this.tagName
49
+
50
+ // sameValuZero algorithm
51
+ const sameValueZero = ( a , b ) => {
52
+ if ( a === b || ( Number . isNaN ( a ) && Number . isNaN ( b ) ) ) {
53
+ return true ;
54
+ }
55
+
56
+ return false ;
57
+ } ;
58
+
59
+ // Output
60
+ // ==, ===, object.is, sameValuZero algorithm
61
+ const array = [ NaN ] ;
62
+
63
+ const result = array . includes ( NaN ) ;
64
+ console . log ( result ) ; // True: why? => array.includes follows sameValueZero algorithm
0 commit comments