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
| 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
| 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
| 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 new_car = new Promise((resolve, reject) => { | |
| setTimeout(() => { | |
| resolve("This is the car.Enjoy!!!"); | |
| }, 3000); | |
| }); | |
| new_car.then( | |
| (value) => { | |
| alert(value); //ths code runs because promise resolves | |
| }, |
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 new_car = new Promise((resolve, reject) => { | |
| setTimeout(() => { | |
| resolve("This is the car.Enjoy!!!"); | |
| }, 3000); | |
| }); | |
| new_car | |
| .then((value) => { | |
| alert(value); //ths code runs because promise resolves | |
| }) |
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
| let check_files = function () { | |
| return new Promise((resolve, reject) => { | |
| resolve("I checked files, "); | |
| }); | |
| }; | |
| let make_calls = function (message) { | |
| return new Promise((resolve, reject) => { | |
| resolve(message + "," + "I made all important calls"); | |
| }); | |
| }; |
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
| var x =[1,2,3]; | |
| console.log(x); //[1,2,3] | |
| console.log(...x); //1 2 3 |
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
| var str = "Football"; | |
| var arr =[1,2,3]; | |
| console.log(...str); // F o t b a l l | |
| console.log(...arr); // 1 2 3 |
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
| let x = [1,2,3]; | |
| let y = [4, 5,6]; | |
| console.log([...x,...y]); ///[1,2,3,4,5,6] |