Thursday, 7 March 2013

Using Static Variable in JavaScript

The following code snippet explains how we can use static variables
in JavaScript.  
 
function foo() {

    if( typeof foo.counter == 'undefined' ) {
        foo.counter = 0;
    }
    foo.counter++;
    document.write(foo.counter+"<br />");
}

No comments:

Post a Comment