// Fetch JSON data from an API using the Fetch API
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
code
Fetch JSON Data from API in JavaScript
This JavaScript code uses the Fetch API to make an asynchronous request to the JSONPlaceholder API and fetches data for the post with ID 1. The retrieved JSON data is then logged to the console. The comments provide explanations for each part of the code.
Fetch API
JSON
Asynchronous