@@ -62,3 +62,87 @@ const array = [NaN];
6262
6363const result = array . includes ( NaN ) ;
6464console . log ( result ) ; // True: why? => array.includes follows sameValueZero algorithm
65+
66+ // Output
67+ const p = Promise . resolve ( "Hello" ) ;
68+ p . then ( ( val ) => {
69+ console . log ( val ) ;
70+ return `${ val } world` ;
71+ } ) . then ( ( newVal ) => {
72+ console . log ( "new " , newVal ) ;
73+ } ) ;
74+
75+ // Output => level => easy
76+ function * counter ( ) {
77+ let index = 0 ;
78+ while ( true ) {
79+ yield index ++ ;
80+ }
81+ }
82+
83+ const gen = counter ( ) ;
84+
85+ console . log ( gen . next ( ) . value ) ;
86+ console . log ( gen . next ( ) . value ) ;
87+ console . log ( gen . next ( ) . value ) ;
88+
89+ // Output
90+ var y = 1 ;
91+ if ( function f ( ) { } ) {
92+ y += typeof f ;
93+ }
94+
95+ console . log ( y ) ;
96+
97+ // Output
98+ var k = 1 ;
99+ if ( 1 ) {
100+ eval ( function foo ( ) { } ) ;
101+ k += typeof foo ;
102+ }
103+
104+ console . log ( k ) ;
105+
106+ // Output
107+ var k = 1 ;
108+ if ( 1 ) {
109+ function foo ( ) { }
110+ k += typeof foo ;
111+ }
112+ console . log ( k ) ;
113+
114+ // Write a function that would allow you to do this 👉🏻 multiply(5)(6)
115+
116+ // Ans:
117+ function multiply ( a ) {
118+ return function ( b ) {
119+ return a * b ;
120+ } ;
121+ }
122+
123+ multiply ( 5 ) ( 6 ) ;
124+
125+ // Explain what is callback function is and provide a simple example
126+
127+ function modifyArray ( arr , callback ) {
128+ arr . push ( 100 ) ;
129+
130+ callback ( ) ;
131+ }
132+
133+ let arr = [ 1 , 2 , 3 , 4 , 5 ] ;
134+
135+ modifyArray ( arr , ( ) => {
136+ console . log ( "Array has been modified " , arr ) ;
137+ } ) ;
138+
139+ // Given a string, reverse each word in the sentence
140+ const reverseBySeparator = ( str , separator ) =>
141+ str . split ( separator ) . reverse ( ) . join ( separator ) ;
142+
143+ const str = "Welcome to this Javascript Guide!" ;
144+ const reverseEntireSentence = reverseBySeparator ( str , "" ) ;
145+
146+ const reverseEachWord = reverseBySeparator ( reverseEntireSentence , " " ) ;
147+
148+ console . log ( reverseEntireSentence , reverseEachWord ) ;
0 commit comments