File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Document</ title >
7+ </ head >
8+ < body >
9+ < h1 id ="heading "> Namaste JavaScript</ h1 >
10+
11+ < button id ="clickMe "> Click Me</ button >
12+
13+ < script src ="./Ep-14-Callback-Functions.js "> </ script >
14+ </ body >
15+ </ html >
Original file line number Diff line number Diff line change 1+ // What is a callback Function in Javascript ?
2+
3+ // 🟨Functions are first class citizens in javascript
4+ // function pass into another function is called Callback Function.
5+
6+ setTimeout ( ( ) => {
7+ console . log ( "Timer⏰" ) ;
8+ } , 1000 ) ;
9+ function x ( y ) {
10+ console . log ( "x" ) ;
11+ y ( )
12+ }
13+ x ( function z ( ) {
14+ console . log ( "y" ) ;
15+ } )
16+
17+ //-----------------------------------------------------------
18+ // Javascript is synchronous and single-threaded language
19+
20+
21+ // -----------------------------------------------------------
22+ // Blocking the main thread
23+
24+
25+ // -----------------------------------------------------------
26+ // Power of Callbacks ?
27+
28+
29+ // -----------------------------------------------------------
30+ // Deep about Event Listeners
31+
32+
33+ // -----------------------------------------------------------
34+ // Clossures demo with Event Listeners
35+
36+
37+ // -----------------------------------------------------------
38+ // Scope demo with Event Listeners
39+
40+
41+ // -----------------------------------------------------------
42+ // Garbage Collection & removeEventListeners
43+
44+
45+
46+ function attachEventListener ( ) {
47+ let count = 0
48+ document . getElementById ( 'clickMe' ) . addEventListener ( "click" , ( ) => {
49+ console . log ( "Button Click" , ++ count ) ;
50+ } ) ;
51+ }
52+ attachEventListener ( )
You can’t perform that action at this time.
0 commit comments