Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

11 Scope


Variables can be global or local.

Variables are global if created outside a function .

Variables are local if created inside a function .  Use var to create a local variable
of the same name as a global variable

It 's allowed to have a global and local variable of the same name.

If a local variable by the same name of a global variable is required, the var declaration must be used inside the function , otherwise
references to the variable will refer to the global variable.

Functions are always global (can be accessed from any JavaScript on the page)