Asynchronous Immediately Invoked Function Expression

DEPRECATED!!! but fun =))

Nowadays all JavaScript engines support a top-level await. So, we don’t need to write all this nonsense;) anymore.

type Todo = {
  userId: number
  id: number
  title: string
  completed: boolean
}

const url = "https://jsonplaceholder.typicode.com/todos"

;(async function getData() {
  const res = await fetch(url)
  const data: Todo[] = await res.json()

  console.log(data.slice(0, 10))
  console.log(data[0]?.title)
})()