Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Practicing spread operator, promise and regex.
- Loading branch information
1 parent
e249795
commit d9b64e4
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//Spread Operator | ||
|
||
const obj = { | ||
name: "Eliab", | ||
age: 24, | ||
country: "Nicaragua" | ||
} | ||
|
||
let {name, ...all} = obj; | ||
console.log(`Name: ${name}`); | ||
console.log(`Additional Information:`, all); | ||
|
||
let {country, ...otherInfo} = obj; | ||
console.log(`Country: ${country}`); | ||
console.log(`Name and age:`, otherInfo); | ||
|
||
const obj1 = { | ||
name: "Eliab", | ||
age: 24 | ||
} | ||
|
||
const obj2 = { | ||
...obj1, | ||
country: "Nicaragua" | ||
} | ||
|
||
console.log(obj2); | ||
|
||
const helloWorld = () => { | ||
return new Promise((resolve, reject) => { | ||
true | ||
? setTimeout(() => { | ||
resolve("Hello World!"); | ||
},3000) | ||
: reject(new Error("Test Error")); | ||
}); | ||
} | ||
|
||
helloWorld() | ||
.then((result) => { | ||
console.log("Result: ",result); | ||
}) | ||
.catch((err) => { | ||
console.log("Error: ",err); | ||
}) | ||
.finally(() => { | ||
console.log("¡Finalizó!"); | ||
}); | ||
|
||
const regexData = /([0-9]{4})-([0-9]{2})-([0-9]{2})/; | ||
const match = regexData.exec('2018-04-28'); | ||
const year = match[1]; | ||
const month = match[2]; | ||
const day = match[3]; | ||
console.log(match); | ||
console.log('Date:', year, month, day); |