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
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
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 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
var words = ["This", "is", "john", "Doe"]; | |
var first = words[0]; | |
var second = words[1]; | |
console.log(first); //This | |
console.log(second); // is |
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 words = ["This", "is", "john", "Doe"]; | |
var [first, second] = words; | |
console.log(first); //This | |
console.log(second); //is |
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 [first, second, third] = "USA"; | |
console.log(first); //U | |
console.log(second); //S | |
console.log(third); //A |
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 words = ["This", "is", "john", "Doe"]; | |
var [first, , third] = words; | |
console.log(third); //john |
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 words = ["This", "is", "john", "Doe"]; | |
var [first, ...last] = words; | |
console.log(last); //["is","john","Doe"]; |