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

Misleading javascript conflict example #37549

Open
funmise opened this issue Jan 7, 2025 · 0 comments
Open

Misleading javascript conflict example #37549

funmise opened this issue Jan 7, 2025 · 0 comments
Labels
Content:Learn:JavaScript Learning area JavaScript docs

Comments

@funmise
Copy link

funmise commented Jan 7, 2025

MDN URL

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

What specific section or headline is this issue about?

Function scope and conflicts

What information was incorrect, unhelpful, or incomplete?

The example provided under the "Function scope and conflicts" section could be misleading as it implies that JavaScript always prioritizes the greeting() function from the first.js file, ignoring the greeting() function from second.js. While this is the observed behavior due to the const redeclaration error halting the execution of second.js, it could give the impression that JavaScript automatically "prefers" the first declared function in cases of conflicts, which is not true.

This could confuse beginners into thinking that JavaScript inherently ignores duplicate functions in later scripts, which contradicts standard behavior where later declarations overwrite earlier ones unless there's a blocking error.

What did you expect to see?

A clearer explanation about why second.js fails to execute in this specific example, emphasizing:

  • The role of the const redeclaration error in halting the execution of second.js.
  • The typical behavior of JavaScript, where functions and variables declared later overwrite earlier ones unless an error stops execution.

Additionally, a more robust example demonstrating this behavior could be helpful. For instance:

Using let or var instead of const to show how the greeting() function from second.js would overwrite the one from first.js.
Explicitly highlighting that errors like const redeclarations affect execution flow.

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

No response

Do you have anything more you want to share?

No response

MDN metadata

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

No branches or pull requests

2 participants