I have this js snippet,
let checker={flag:0,dirtyFlag:false};
let i=0;
setTimeout(()=>{
console.log('value of checker updated');
checker.dirtyFlag=true;
checker.flag=1;
},2000)
while (true) {
console.log(i++);
if(checker.flag==1){
console.log(checker.dirtyFlag);
break;
}
}
but the code runs endless, whereas expected behavior is, it should stop after 2000ms.
how can i debug the above code.