how to wait until a variable is set javascript 1

how to wait until a variable is set javascript

function waitForElement(){
    if(typeof someVariable !== "undefined"){
        //variable exists, do what you want
    }
    else{
        setTimeout(waitForElement, 250);
    }
}

Here is what the above code is Doing:
1. It checks if the variable exists.
2. If it does, it does what you want.
3. If it doesn’t, it waits 250 milliseconds and then tries again.

Similar Posts