This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| promise.then( | |
| (value) => { | |
| /* run when promise resolved */ | |
| }, | |
| (error) => { | |
| /* run when promise rejected */ | |
| } | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const promise = new Promise((resolve, reject) => { | |
| has_money = false; | |
| setTimeout(() => { | |
| if (has_money) { | |
| resolve("Here is your car. Enjoy your ride"); | |
| } else { | |
| reject("Sorry, I don't have money to buy car"); | |
| } | |
| }, 5000); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const promise = new Promise((resolve, reject) => { | |
| has_money = true; | |
| setTimeout(() => { | |
| if (has_money) { | |
| resolve("Here is your car. Enjoy your ride"); | |
| } else { | |
| reject("Sorry, I don't have money to buy car"); | |
| } | |
| }, 5000); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function square(x,result = x *x ) { | |
| console.log(result); | |
| } | |
| square(5); //25 | |
| square(6) ; //36 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function number() { | |
| return 10; | |
| } | |
| function result (x ,y =number()) { | |
| console.log(x+y); | |
| } | |
| result(2); //12 | |
| result(10,20) //30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function identity(name = "John",age = 25) { | |
| console.log(name, " ", age); | |
| } | |
| identity(); //John 25 | |
| identity("Harris"); //Harris 25 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function abc(x,y) { | |
| if (x === undefined) { | |
| x = 100; | |
| } | |
| if (y === undefined) { | |
| y = 50; | |
| } | |
| console.log(x,y); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function abc(x,y) { | |
| //we used logical OR(||) operator. It returns the first truthy value. | |
| //if first value is undefined, second value is returned | |
| x = x || 100; | |
| // value of x is x which is given at the function call. If not given value is 100 | |
| y = y || 50; | |
| // value of y is y which is given at the function call. If not given value is 50 | |
| console.log(x,y); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function abc(a,b) { // a and b are called parameters | |
| //code | |
| } | |
| abc(c,d); // c and d are called arguments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //style.css | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; } | |
| body { | |
| width: 100%; | |
| height: 100vh; | |
| background-color: #0f3057; |