JavaScript shutdown and memory management

I'm curious how the variables inside closures are handled with memory. Take this code, for example -

function iAmAClosure() {
    var txtName = document.getElementById('name');

    function validation() {
        if (txtName.value.length === 0) {
            return false;
        }
        return true;
    }

    document.getElementById('submit').onclick = function () {
        return validation();
    }
}

My function validationis called whenever the user clicks a button.

My question is, does the variable remain txtNamein memory as long as the page is active, or is it GC'ed and initialized every time a method check is called? Is there anything else for this?

What is the higher performance?

+3
source share
1 answer

, . txtName onclick, , onclick "" .

+4

All Articles