A friend of mine and I are currently discussing what is a closure in JS and what isn't. We just want to make sure we really understand it correctly.

Let's take this example. We have a counting loop and want to print the counter variable on the console delayed. Therefore we use `setTimeout` and **closures** to capture the value of the counter variable to make sure that it will not print N times the value N.

The wrong solution without **closures** or anything near to **closures** would be:

```
for(var i = 0; i < 10; i++) {
    setTimeout(function() {
        console.log(i);
    }, 1000);
}

```

which will of course print 10 times the value of `i` after the loop, namely 10.

**So his attempt was:**

```
for(var i = 0; i < 10; i++) {
    (function(){
        var i2 = i;
        setTimeout(function(){
            console.log(i2);
        }, 1000)
    })();
}

```

printing 0 to 9 as expected.

I told him that he isn't using a **closure** to capture `i`, but he insists that he is. I proved that he doesn't use **closures** by putting the for loop body within another `setTimeout` (passing his anonymous function to `setTimeout`), printing 10 times 10 again. The same applies if I store his function in a `var` and execute it *after* the loop, also printing 10 times 10. So my argument is that **he doesn't really *capture* the value of `i`**, making his version *not* a closure.

**My attempt was:**

```
for(var i = 0; i < 10; i++) {
    setTimeout((function(i2){
        return function() {
            console.log(i2);
        }
    })(i), 1000);
}

```

So I capture `i` (named `i2` within the closure), but now I *return* another function and pass this around. **In my case, the function passed to setTimeout really captures `i`.**

**Now who is using closures and who isn't?**

Note that both solutions print 0 to 9 on the console delayed, so they solve the original problem, but we want to understand which of those two solutions **uses closures** to accomplish this.