Where can I declare Global Variables

R

rick

Noob problem. I prefer to keep all my scripts in an external '.js' file.
I am currently loading the external '.js' file from the header. Problem is I
would like to declare
a global variable in the external file, but I keep getting an error about
the object does not exist.

Can someone tell me where or how to declare a global variable in an external
file that is
available after the page is loaded.

Thanks in advance.
 
R

rick

I found the answer: Do not use 'var' to declare the variable.
Just declare it!! i.e. 'newvar = 0;'
 
L

Lasse Reichstein Nielsen

Please don't top post.
I found the answer: Do not use 'var' to declare the variable.
Just declare it!! i.e. 'newvar = 0;'

That shouldn't make a difference, if the declaration is not inside a
function body. Then the declaration will declare the global variable,
just as simply assigning to an undeclared variable.
/L
 
R

rick

That shouldn't make a difference, if the declaration is not inside a
function body. Then the declaration will declare the global variable,
just as simply assigning to an undeclared variable.

That is what I did. Sorry still learning..........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top