What is the Fetch API?
The Fetch API provides a modern and flexible way to make HTTP requests in JavaScript. It replaces older methods like `XMLHttpRequest` and provides a cleaner, promise-based approach for handling requests.
Basic Syntax of Fetch
To use the Fetch API, simply call the `fetch()` function, passing in the URL of the resource you want to fetch.
fetch('https://api.example.com/data') // Fetch data from an API
Example: Fetching Data
In this example, we will use the Fetch API to fetch data from a simulated API and display the result below.