What is the difference between async arrow function and async IIFE?

Can someone please help me understand the difference (if there is a difference) in how these blocks are executed:

;(async function(){
  await alert('Hello world!');


let myFunction = async () => {
  await alert('Hello world!');

Apart from the fact that the IIFE is immediately self-invoked, is there any difference in how these blocks are executed?

1 answer

  • answered 2018-03-13 20:38 Deadron

    Your example is not a good example because you are not performing an asynchronous action within your async function. alert is synchronous, as in javascript execution will halt until it returns. This makes the await keyword usage here pointless.

    The only difference I see is that you are not assigning the resulting promise to a variable in the iife, which means if you were performing an async action you would not be able to execute code when it is finished.