Question: Learning JS here, I run JSLint on this code:

```
/*jslint devel: true*/

function Animal(n) {
    "use strict";
    this.name = n;
    this.prop = "a";
}

var a = new Animal("duppa");

for (v in a) {
    if (a.hasOwnProperty(v)) {
        console.log("property:" + v);
    }
}

```

I get:

```
jslint:test2.js:11:6:'v' was used before it was defined.
jslint:test2.js:11:8:Cannot read property "kind" from undefined

jslint: ignored 0 errors.

```

It obviously complains that I did not declare `v` up front:

```
/*jslint devel: true*/

function Animal(n) {
    "use strict";
    this.name = n;
    this.prop = "a";
}

var a = new Animal("duppa");

var v;
for (v in a) {
    if (a.hasOwnProperty(v)) {
        console.log("property:" + v);
    }
}

```

This shuts JSLint up, but is it really necessary? In general I try to follow good conventions but is this one really necessary in JS? E.g. Python lives happily without such stuff (`for x in range(10)...` etc).

Answer: 
Yes, you **absolutely** should declare the variable. Otherwise you're declaring `v` at global scope which is never good, but it's particularly bad for counting variables which are a single letter long like `v`.

Consider the case where two people get lazy about declaring a variable of the same name:

```
// Your code, which iterates over a nested array

var arr = [ [1, 2], [3, 4] ];

for (i = 0; i < arr.length; ++i) {
  AwesomeLibrary.doSomething(arr[i]);
}

// way down elsewhere, in awesome_library.js...

function doSomething(arr) {
  for (i = 0; i < arr.length; ++i) {
    // Now your `i` is clobbered, and we have a subtle but devastating bug
  }
}

```

This doesn't even require two lazy people: If you work with JavaScript long enough and refuse to declare your variables, you will eventually do this to yourself.
Remember that JSLint doesn't complain because of some obscure academic reason but because it protects you from major problems your application may potentially suffer from.

You declare a variable to contain the variable in the current scope. It's a safeguard for you and your program as well making it more readable code (global vars appearing out of nowhere are always confusing).

Imagine if you had a global variable v in your application and then used the same nomenclature (`v`) for iteration in a function. Javascript will automatically assume that the global variable is being used and you'll find yourself with unwanted values in your global. Having said that, the less stuff you put in the global namespace the better.