Question: My question is, if I have a function like this 

```
function f(a) {
if (a == undefined) {
    alert(1)
    return f
} else {
    alert(2)
}

```

}

and I call it like this, for example, `f()()()()('123')`, how can I keep track of how many times f was called? 

Edit:
I had a play around and worked out a solution:

```
function f(a) {
if (!f.count) {
    f.count = 0;
}
if (a == undefined) {
    alert(1);
    ++f.count;
    return f;
} else {
    f.count = 0;
    alert(2);
}

```

}

alert(1) and alert(2) are essentially placeholders for the moment. The count variable would be used in the else section in the actual function.
Thank you all for your help.

Answer: 
Just create a count variable outside of the function scope and whenever you enter the function, you increase its value.

```
var count = 0;

function f(a) {
    count++;

    if (!a) {
        alert(1);
        return f;
    } else {
        alert(2);
    }
}

```
By "wrapper function) do you mean "closure"?

```
var f = (function (a) {
  var count = 0; 

  return function () { 
    console.log(count);
    count += 1;

    if (!a) {
      alert(1);
      return f;
    } else {
      alert(2);
    }
  }

})();

```