How to async await fetch in JavaScript

JSON
By Jad Joubran · 
Last updated Feb 13, 2024
(async () => {
  try {
    const response = await fetch("https://codetogo.io/api/users.json");
    const data = await response.json();
    console.log(data);
  } catch (err) {
    console.error(err);
  }
})();
[{
    id: 1,
    name: "Sam"
}, {
    id: 2,
    name: "Alex"
}]
Fetch API use cases on Learn JavaScript