Varible Global not woking

hi everyone, I need your help I have a simple code

var globalvar = 0; // this is my variable global

// this is my controller
var timestore = zupafactoryio.ZupaTimeStore(id); // show my timestore


            if( resp.id_category == id){

                if( dias[store_day] == resp.day_name){

                    if( < store_complete && resp.close > store_complete ){

                        globalvar = 1; // open store





/// the problem is the globalvar not working, when out of the foreach the var globalvar have to value zero,
/// and not take val 1
if( globalvar == 1 ){
console.log('cool the var global working '+globalvar);
console.log(‘the var globalvar not working’);


when out of the bucle foreach the var globalvar not working.
please why not working my var global, I don’t understand please helpme

Where are you attempting the if to check if globalvar is equal to 1? Remember, ZupaTimeStore returns a promise so it’s async. If you’re trying to do the if after the then function it won’t work, and will show a value of 0.

hi, and thanks, how to resolve this problem please tell me