Q:

Why can I not successively increment a variable within a function?

I'm trying to add 10 over and over for every invocation of d. It stays 20 every time, why?
function d() {
    var c = [10];
    c[0] += 10;
    alert(c[0]); // always 20
}
d(); d(); d(); // supposed to be 20, 30, 40...

A:

You create a new array and assign it to c each time the function is called. That resets it.
Move the assignment so it is outside the function (so it only runs once).
var c = [10];
function d() {
    c[0] += 10;
    alert(c[0]);
}
d(); d(); d(); // will be 20, 30, 40...

But globals are good source of bugs, so it is considered good style to wrap such things in closures to minimise the use of globals.
var d =(function () {
    var c = [10];
    function d() {
        c[0] += 10;
        alert(c[0]);
    };
    return d;
})();
d(); d(); d();

