How to add static variables in javascript?

    You can do this by using following code
    function staticNew() {
        // Check if counter is already intialized
        if ( typeof staticNew.counter == 'undefined' ) {
            // Initialize variable to 0
            staticNew.counter = 0;
        }

        // Show the static value each time the function is called
        alert(++staticNew.counter);
    }
    4
    Average: 4 (1 vote)