I want to get a js variable as soon as it's defined.
I tried this:
function waitForCondition(variable) {
    function waitFor(result) {
        if (result) {
            return result;
        }
        return new Promise((resolve) => setTimeout(resolve, 100))
            .then(() => Promise.resolve([variable]))
            .then((res) => waitFor(res));
    }
    return waitFor();
}
But this will return even on false e.g.:
let variable = false;
waitForCondition('variable').then((res) => { console.log(variable); });
variable = 123;
How to return the variable once it's set and not false?
 
     
    