Wait until variable equals

Viewed 5643

I am trying to check if a variable is equal to 1 using javascript...

myvalue = 1;

function check() {
    if (myvalue == 1) {
        return setTimeout(check, 1000);
    }

    alert("Value Is Set");
}

check();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

I am planning on adding a delay to the setting of the variable but for now why is this simple version not working?

1 Answers
Related