Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:26:18+00:00 2026-06-05T06:26:18+00:00

Never met this problem, and don’t know why. The only explanation is a scope

  • 0

Never met this problem, and don’t know why.
The only explanation is a scope issue.

In the same page, I have 2 sections of JS :

...
 <script type="text/javascript">
    go();
  </script>

  <script type="text/javascript">
    function go()
    { alert('');  }
  </script>
...

This will show an error : go is not defined

where

...
     <script type="text/javascript">
        go();

        function go()
        { alert('');  }
      </script>
    ...

is working (obviously).

Does <script> tag creates a scope of JS ?
help ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:26:20+00:00Added an answer on June 5, 2026 at 6:26 am

    This isn’t a scope issue. If you define a function (in the global scope) in one script element, then you can use it in another.

    However, script elements are parsed and executed as they are encountered.

    Hoisting won’t work across script elements. A function defined in a later script element won’t be available during the initial run of an earlier script element.

    You either need to swap the order of your script elements, or delay the function call until after the script that defines it has run (e.g. by attaching it to an onload event handler).

    <script>
        function go() {
            alert('');  
        }
    </script>
    <script>
        go();
    </script>
    

    or

    <script>
        window.addEventListener("load", function () { 
            go();
        }, false);
    </script>
    <script>
        function go() {
            alert('');  
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Never thought I'd have this problem :) The following snippet of code works in
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I have problem I have never met before. I was clearing yesterday clients db
I met strange problem. I have never work with Devise gem before. So, i
Ive never heard of this before, and I have been coding in PHP for
I will try to make this simple and quick.. I have never attempted this
I am programming in C++ more then 5 years, and have never met any
Never had a problem trying to do this before. I am attempting to centre
I never really know what order is the best installation or if it even
I never clearly understood what an ABI is. Please don't point me to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.