File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
JavaScript/Advance/Async/2.Asynchhronous Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8+ < title > Asynchronous</ title >
9+ < link rel ="shortcut icon " href ="images/js-logo.png " type ="image/x-icon ">
10+ </ head >
11+
12+ < body >
13+ < h2 id ="textOne "> </ h2 >
14+ < h2 id ="textTwo "> </ h2 >
15+ < script src ="script.js "> </ script >
16+ </ body >
17+
18+ </ html >
Original file line number Diff line number Diff line change 1+ /*
2+ In Asynchronous functions run parallel to each other which are called Asynchronous
3+ Best example is setTimeOut()
4+ and setInterval()
5+ */
6+
7+ // Example of setTimeOut
8+
9+ function DisplayOne ( ) {
10+ let text = "Hey There!" ;
11+ document . getElementById ( 'textOne' ) . innerHTML = text ;
12+ }
13+
14+ setTimeout ( DisplayOne , 2000 ) ; //Here we have called a function and also defined after how many miliseconds will the function load
15+
16+
17+ // Example of setInterval()
18+
19+ function DispTwo ( ) {
20+ let x = new Date ( ) ;
21+ let time = x . getHours ( ) + " : " + x . getMinutes ( ) + " : " + x . getSeconds ( ) ;
22+ document . getElementById ( 'textTwo' ) . innerHTML = time ;
23+ }
24+
25+ setInterval ( DispTwo , 1000 ) ;
You can’t perform that action at this time.
0 commit comments