[thelist] Javascript: Global variables in external .js?

Emma Jane Hogbin emmajane at xtrinsic.com
Sat Mar 8 16:35:01 CST 2003

On Sat, Mar 08, 2003 at 04:57:21PM -0500, Frank wrote:
> I've tried setting my variables at the top of the page, hoping that each
> function could make use of it, but apparently that's not the case.

It is the case! According to the O'Reilly book on Javascript (the one with
the rhino):
	... variables declared withing a function are defined only within
	the body of the function. They are local variables and have local
	scope. Function parameters also count as local variables and are
	defined only within the body of the function.

	Within the body of a function, a local variable takes precedence
	over a global variable with the same name. If you declare a [local
	variable with the same name] you effectively hide the global

Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]

More information about the thelist mailing list