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 a = "first"; | |
var b = "second"; | |
var [a, b] = [b, a]; | |
console.log(a); //second | |
console.log(b); //first |
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 [firstName = prompt("What is your name?"), surname = prompt("surname?")] =["John"]; | |
alert(firstName); | |
alert(surname); |
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="This", second = "is"] =["hello"]; | |
console.log(first); //hello | |
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
function words() { | |
return ["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 words = ["This", "is", "john", "Doe"]; | |
var [first, ...last] = words; | |
console.log(last); //["is","john","Doe"]; |
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 [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, 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 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
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); |