Skip to main content

One post tagged with "async/await"

View All Tags

ยท One min read
Kumar Nitesh
// fetching data from an API with basic promise syntax (notice the use of arrow functions)window  .fetch("http://jsonplaceholder.typicode.com/posts")  .then((response) => response.json())  .then((data) => console.log(data));
// fetching same data from API with async/await    async function getPostData() {         const response = await window.fetch( "http://jsonplaceholder.typicode.com/posts" );        // we need to resolve two promises using await to get the final data         const data = await response.json();         console.log(data);     }     getPostData();