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 asyncFunc = async () => { | |
const data = await fetchData() | |
const userData = await fetchUserData(data) | |
updateUserState(userData) | |
return | |
} |
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 data = fetchData() | |
const userData = fetchUserData(data) | |
updateUserState(userData) |
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
fetchData().then((data) => { | |
fetchUserData(data).then((userData) => { | |
updateUserState(userData) | |
}) | |
}) |
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 myPromise = new Promise((resolve, reject) => { | |
fetch('https://jsonplaceholder.typicode.com/todos/1') | |
.then(res => res.json().then((json) => resolve(json))) | |
}) | |
myPromise.then((res) => doSomething(res)).then(() => console.log("Okey now i'm done!")) |
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 myPromise = new Promise((resolve, reject) => { | |
fetch('url').then(res => res.json().then((json) => resolve(json))) | |
}) | |
myPromise.then(res => console.log(res)) // json data |
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 myPromise = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve("I'm resolved") | |
}, 3000) | |
}) | |
myPromise.then(res => console.log(res)) // I'm resolved |
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 doesIncludeFlorida = userDetails[0].includes('Florida') // true |
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 filteredUser = allUsers().filter(user => user.state !== 'Florida') |
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 getUser = (userData) => { | |
const [ name, surName, country, state, joined, age ] = userData.split(',') | |
return { name, surName, country, state, joined, age } | |
} | |
const allUsers = (users) => { | |
// forEach... | |
const user = getUser(users[0]) | |
return [user] //returning array so we can filter, map etc.. | |
} | |
allUsers(['John,Doe,USA,Florida,1995,50']) |
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 [ name, surName, country, state, joined, age ] = userDetails.split(',') | |
return { name, surName, country, state, joined, age } | |
// {name: "John", surName: "Doe", country: "USA", state: "Florida", joined: "1995", age: "50"} |