I’m using async/await. Why Does My Function Return a Promise?

async function asyncCheckPokemon() {
const response = await fetch("https://pokeapi.co/api/v2/pokemon/25");
const pikachuJSON = await response.json();
// Prints "Look mum, no callbacks! Pokémon #25 is pikachu"
console.log(
`Look mum, no callbacks! ` +
`Pokémon #${pikachuJSON.id} is ${pikachuJSON.name}`
);
}
asyncCheckPokemon();
async function asyncCheckPokemon() {
const response = await fetch("https://pokeapi.co/api/v2/pokemon/25");
const pikachuJSON = await response.json();
return (
`Look mum, no callbacks! ` +
`Pokémon #${pikachuJSON.id} is ${pikachuJSON.name}`
);
}
const pikachuMessage = asyncCheckPokemon();
async function asyncCheckPokemon() {
const response = await fetch("https://pokeapi.co/api/v2/pokemon/25");
const pikachuJSON = await response.json();
return (
`Look mum, no callbacks! ` +
`Pokémon #${pikachuJSON.id} is ${pikachuJSON.name}`
);
}
async function printPikachuMessage() {
const pikachuMessage = await asyncCheckPokemon();
// Prints "Look mum, no callbacks! Pokémon #25 is pikachu"
console.log(pikachuMessage);
}
printPikachuMessage();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store