Question: I am reading a section about closures in a JS book, and reached an example in the section showing 'getter/Stetter' functions...

```
var getValue, setValue;

(function (){

    var secret = 0;

    getValue = function(){
    return secret;
    }
    setValue = function(v){
    secret = v;
    }

})();

setValue(5);
getValue();
5 //get 5

```

1) I thought omitting 'var' made variables global?

2) From time to time I hear folks talking about 'getters/Setters', What would be a practical use of them?

Thanks!

Answer: 
> 
> Why is the 'secret' variable not global?
> 
> 
> 

Because it is declared using `var`.

```
var secret = 0;

```

> 
> I thought omitting 'var' made variables global?
> 
> 
> 

One use of `var` in a function will make all variables declared in that statement local.
Because it's defined within `(function() { ... })`. If you want to make it global, declare it alongside your `getValue` and `setValue`.

The `var` keyword simply declares a variable, it doesn't make it global:

```
var secret = "Global";        // Global variable declaration

function myFunction() {
    var secret;               // Local to myFunction()
    secret = "Hello, world!"; // Only local secret variable changed
    console.log(secret);      // "Hello, world!"
}

console.log(secret);          // "Global"

```

Dropping the `var` will only make it global if the variable has already been defined in the global scope:

```js
var secret = "Global";        // Global variable declaration

function myFunction() {
    secret = "Hello, world!"; // Global secret variable changed
    console.log(secret);      // "Hello, world!"
}

console.log(secret);          // "Hello, world!"

```