Created
February 13, 2022 23:10
-
-
Save bbenjamin/35f31b9d66517866cc2f65528bba77a1 to your computer and use it in GitHub Desktop.
Async await vs promise chain
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 callDataMuse = function() { | |
const parseJson = function(response) { | |
return response.json(); | |
} | |
const logParsedJson = function(parsedJson) { | |
console.log('parsed json!', parsedJson); | |
} | |
fetch('https://api.datamuse.com/words?sl=butter') | |
.then(parseJson) | |
.then(logParsedJson) | |
} | |
callDataMuse(); | |
// THIS ALSO WORKS | |
const callDataMuse2 = async function() { | |
const parseJson = async function(response) { | |
return response.json(); | |
} | |
const logParsedJson = function(parsedJson) { | |
console.log('parsed json!', parsedJson); | |
} | |
const response = await fetch('https://api.datamuse.com/words?sl=butter'); | |
const parsedJson = await parseJson(response); | |
logParsedJson(parsedJson); | |
} | |
callDataMuse2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment