Scope of variables

I have document that consists of 3 parts (top, bottom, details). I also have a script where I calculate the height of the top. The selector for this script is “body”, so that is pretty much global.
I also have another script per field that loops through all the records in my source (XML). The selector for this script is “tbody tr td” and I also have a Find text filled in there.
I would expect the variables I created in the earlier script to be available in the script for my table. Note that I used the var keyword to create the variables.
I also cannot copy the code I used to fill the variables in the script that has the “body” scope to my table script as the scope for the table script is much more limited and I do not have access there to css of the top block on my page.
Is there a way to access variables that are global in scope (with the body selector) and access them in my table script?

Variables declared with var only exist for the script scope. If you want a “globale variable”, simply define it without the var.

When using global variables (declaration without var) you also have to pay attention to the order of the scripts in the scripts folder. Scripts that want to access a global variable in another script must be placed below the script with the corresponding global variable.

For example:
Script1 contains a global variable.
Script2 wants to access the global variable.
Sequence: Script1 must be on top, Script2 below.

That makes sense. Thanks. It seems to be working.
Another followup question…Post pagination scripts do not have access to global variables because they run when everything is completed, right?

Just tried it and Post pagination script do have access to global variable. Post pagination script are just run at the end of the pagination process.