Please read into the scope of a program. Both scripts are on the same page and share the same global scope
. You can access someNumber
from script block 21, but not from
script block 1` the way you've wrote it:
The scope begins with parsing script block 1
. Script block 2
doesn't exist at this moment.
An example to help you further
<script type="text/javascript" id="script1">
number1=someNumber; //this will generate an error;
function alertNumber()
{
//this isn't executed directly because it's a function.
//We call upon it later in script block 2.
alert(someNumber); //this will work.
}
</script>
<script type="text/javascript" id="script2">
someNumber=7;
alertNumber(); // alertNumber exists since script block 1 is parsed.
</script>
As you can see the flow of the document is top-down. Objects that are in the same scope needs to be declared first before they are called upon. In your code someNumber
wasn't declared yet.
A good page on scope is also on this site.