Skip to content

Update async_and_await.md #29743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Khaspper
Copy link

@Khaspper Khaspper commented May 26, 2025

The update clarifies that we can use await top-level when we are using module scripts

Because

This PR clarifies the behavior of top-level await in JavaScript, specifically noting that it only works in module script

This PR

  • Added clarification that await is not allowed at the top level in non-module scripts
  • Explained how using <script type="module"> in HTML enables top-level await

Issue

Closes #XXXXX

Additional Information

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

The update clarifies that we can use await top-level when we are using module scripts
@KevinMulhern KevinMulhern requested review from a team and JustWaveThings and removed request for a team May 26, 2025 13:28
Copy link
Contributor

@JustWaveThings JustWaveThings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Khaspper,

Thank you for taking the time to make this PR. I apologize for the time it's taken to get to it.

Yes, top level await is a thing and has been for a while. But I'm not sure mentioning it here furthers the the goal of the lesson.

Additionally, depending on environment, there are bugs in how it's been implemented. For example, Safari doesn't allow more than one top level await, and I didn't know that until I researched this PR.

I feel that directing learners to use the async/await syntax at that point in the curriculum is still a valid path forward in 2025. I feel that with many things later in the curriculum, using top level await is something a learner comes across on their own as they do their own research.

I think we could say something like:

Since `await` does not work on the global scope in all environments, lets create an `async` function ... 

If any other maintainer feels strongly about this, feel free to chime in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants