This file contains 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 take_bath = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve("I have finished my bath"); | |
}, 5000); | |
}); | |
let eat = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
reject("I have finished eating"); | |
}, 3000); |
This file contains 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 take_bath = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve("I have finished my bath"); | |
}, 5000); | |
}); | |
let eat = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve("I have finished eating"); | |
}, 3000); |
This file contains 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 sum = function (x, y, z) { | |
return new Promise((resolve, reject) => { | |
let sum = x + y + z; | |
resolve(sum); | |
}); | |
}; | |
let average = function (total) { | |
return new Promise((resolve, reject) => { | |
let average = total / 3; |
This file contains 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 sum(...args) { | |
let sum =0 ; | |
for (let arg of args) { | |
sum += arg; | |
} | |
console.log(sum); | |
} | |
sum(1,2,3,4); // 10 |
This file contains 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(...values) { | |
return values; | |
} | |
console.log(abc(1,2,3)); //[1,2,3]; |
This file contains 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 x = new Date(...[2019, 15, 6]); | |
console.log(x); //script.js:39 Mon Apr 06 2020 00:00:00 GMT+0600 (Bangladesh Standard Time) |
This file contains 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 myFunction() { | |
for (var i in arguments) { | |
console.log(arguments[i]); | |
} | |
} | |
var params =[10,15] | |
console.log(myFunction(5,...params); // 5 10 15 |
This file contains 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 sum = 0; | |
function myFunction() { | |
for (var i in arguments) { | |
sum += arguments[i]; | |
} | |
return sum; | |
} | |
console.log(myFunction(5, ...[5, 5, 5])); //20 |
This file contains 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 sum(x,y,z) { | |
let sum = x + y + z; | |
return sum; | |
} | |
console.log(sum(5,5,5,5)); //15 |
This file contains 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 sum(x,y,z) { | |
return x + y + z; | |
} | |
const numbers =[1,2,3]; | |
console.log(...numbers); //1 2 3 |