DEV Community

Shadiya
Shadiya

Posted on

Fetch in JavaScript

In JavaScript fetch is a function that fetches or retrieves data, the data that we are fetching comes from the json. To do that you would need to pass in an argument, which would be the path to the resource that you are fetching. After you have successfully returned the data using fetch(), you need to add your promises and that can be achieved by using the then() method. The first promise is going to look like:
.then(response => response.json(_)
. The second promise should contain the data from the json and an example of that would be:
.then(data => console.log(data))
. But to be sure that you a grabbing the correct data in the second promise, it's good practice to console.log(). Once the then() method is applied you can make request for data and use them anywhere you want in your code!

Top comments (0)