Skip to content
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

Javascript running order. #37530

Open
wbreeze opened this issue Jan 6, 2025 · 1 comment
Open

Javascript running order. #37530

wbreeze opened this issue Jan 6, 2025 · 1 comment
Labels
accepting PR Feel free to open a PR to resolve this issue Content:Learn:JavaScript Learning area JavaScript docs

Comments

@wbreeze
Copy link

wbreeze commented Jan 6, 2025

MDN URL

https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/What_is_JavaScript

What specific section or headline is this issue about?

https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/What_is_JavaScript#javascript_running_order

What information was incorrect, unhelpful, or incomplete?

"it generally runs it in order, from top to bottom"

"you need to be careful that the objects referenced in your code exist before you try to do stuff to them."

What did you expect to see?

Clearly this is true, that "I have to be careful." Text order isn't the rule, however. ("Generally" is the wiggle word, I guess.) Right in front of me here is a counter example. The code references updateName before the function is defined. Why does that work? The reason uncovers that the ordering is more subtle than simply text, "top to bottom" order.

Do you have any supporting links, references, or citations?

no

Do you have anything more you want to share?

I don't know how to improve this without going too deeply too quickly. Maybe put it in terms of definition before evaluation and noting that button is evaluated by the browser immediately when encountering it in the text?

MDN metadata

Page report details
@wbreeze wbreeze added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Jan 6, 2025
@Josh-Cena
Copy link
Member

We can link to https://developer.mozilla.org/en-US/docs/Glossary/Hoisting, but I agree that we should avoid "going too deeply too quickly", and we should note that updateName is defined after it's accessed, which is fine.

@Josh-Cena Josh-Cena added Content:Learn:JavaScript Learning area JavaScript docs accepting PR Feel free to open a PR to resolve this issue and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting PR Feel free to open a PR to resolve this issue Content:Learn:JavaScript Learning area JavaScript docs
Projects
None yet
Development

No branches or pull requests

2 participants