Listeners for load events can be asynchronous and will be awaited. Listeners for unload events need to be synchronous. Both events cannot be cancelled.

    Example:

    main.ts

    ``

    imported.ts

    ``

    Note that you can use both window.addEventListener and window.onload/ to define handlers for events. There is a major difference between them, let’s run the example:

    `

    `

    In other words, you can register multiple "load" or "unload" events, but only the last loaded window.onload or window.onunload event handlers will be executed. It is preferable to use addEventListener when possible for this reason.