File tree 3 files changed +45
-0
lines changed
JavaScript/Advance/Async/3.Promise 3 files changed +45
-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 > Promise in JS</ title >
9
+ < link rel ="shortcut icon " href ="images/js-logo.png " type ="image/x-icon ">
10
+ </ head >
11
+
12
+ < body >
13
+ < h1 > Promise in JS</ h1 >
14
+ < h2 style ="font-family: cursive; "> Example One</ h2 >
15
+ < p style ="font-family: monospace; " id ="textOne "> </ p >
16
+ < script src ="script.js "> </ script >
17
+ </ body >
18
+
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ /*
2
+ A JavaScript Promise contain two type of code:
3
+ 1. "Consuming Code "
4
+ 2. "Producing Code" : It contains the result and should call one of the callbacks
5
+ ⏩ it will callback the error or the succes
6
+ Understand the following Program how to use promise
7
+ */
8
+ let textOne = document . getElementById ( 'textOne' ) ;
9
+
10
+ function Display ( some ) {
11
+ textOne . innerHTML = some ;
12
+ }
13
+
14
+ let myPromise = new Promise ( function ( Resolve , Reject ) {
15
+ let x = 0 ;
16
+ if ( x == 0 ) {
17
+ Resolve ( "Open script.js file and console for better Understanding !" ) ;
18
+ } else {
19
+ Reject ( "Error just Occured" ) ;
20
+ }
21
+ } )
22
+
23
+ myPromise . then (
24
+ function ( success ) { Display ( success ) } ,
25
+ function ( error ) { Display ( error ) }
26
+ ) ;
You can’t perform that action at this time.
0 commit comments