By 08/02/2016 14 Comments

What is the variable scope in JavaScript?

  • The variable scope is an specific area, from that area any variable can be accessed in program’s other parts.
  • JavaScript has two main variable scope.
  • Global scope: The variable in global scope can be accessed in all parts of the programs such as functions etc and these variables defined outside functions.

Example-1 Global scope:

// global scope.
var siteName = "tutorialstown.";

function getName(){
   document.write("Website is: " + siteName);
}
getName();

  • Local scope: These variables is defined inside any code block such as inside functions and can only be accessed inside these functions. These local variables does not available in another functions.

Example-2 Local scope:


// local scope.
function getName(){
   var siteName = "tutorialstown.";
   document.write("Website is: " + siteName);
}
getName();






Posted in: JavaScript, Solutions

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .