article

global

[WHAT]

  1. ] the term 'global' can refer to different things in javascript 
    1. ] the global object - a native javascript object that 'contains' all the variables that have global scope, as well as its own properties and methods. This object exists for all javascript pages.
    2. ] OR
    3. a 'variable that has global scope' - meaning that the variable can be accessed from anywhere within your web page/site

[WHY]

  1. ] the global object
    1. ]
  2. ] global variables
    1. ] typically you want to avoid using global variables

[WHY NOT]

  1. ] global variables
    1. ] any javascript code can access, read or write, the value of any global variables
    2. ] namespace pollution - the more you use global variables, the more likely that a naming conflict, which will result in NO errors but some unpredictable  

[WHERE]

  1. ] global object
    1. ] a complete listing of the properties and methods of the Global object

[WHEN]

  1. ] global object
    1. ] everywhere - exists for each javascript, created automatically
  2. ] global variables
    1. ] avoid

[EXAMPLE]

  1. ]

[HOW-TO]

  1. ] use the var keyword to specify that your variable will be local to the function that is declared in.
  2. ] var x = "name"; // var will be "local" to the function where it is declared
  3. ] x = "name"; // var will have global scope
  4. ] var x= "name"; // declared outside of any function would also have global scope 

[REFERENCE]

  1. ] https://gist.github.com/hallettj/64478 - a tutorial demonstrating why global variables are bad

  1. ] ?? - helloWorld scope / global object
  2. ] EX js-101-a 
Details Photos Edit more

Details

ID: 2692

NAME: 006-global

DESCRIPTION: by Don Sagrott - Understanding 'global' - the global object and variables with global scope

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: 0

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and