Variable Accessibility in JavaScript
Variable accessibility means how many ways to access the the variable. Its depends on scope of the variable. In javascript there are two types of scope.
1. local scope
2. global scope
JavaScript has function scope: Each function creates a new scope.
Scope determines the accessibility (visibility) of these variables. Variables defined inside a function are not accessible (visible) from outside the function.
var x = 10; function myFunction() { var name = "xyz"; }
Here in example name has the local scope for this function. We can not access it outside of this function but x has global scope because we can access x inside the function and outside of it.
Local variables are created when a function starts, and deleted when the function is completed.
In JavaScript, objects and functions are also variables.