JSFiddle - React, Tailwind, and code Playground
HTML
<button id="myButton">
click Me For Change!!
</button>
JavaScript
var myVar = 0;
var oldVar = 0;
$("#myButton").click(function(){
myVar++;
});
setInterval(function(){
checkForChanges(); // after every 2 secs check
oldVar = myVar; // reset the old value now to the new one, so during next check we should have our myVar changed.
},2000);
function checkForChanges(){
if(oldVar === myVar){
alert('same value nothing has changed!!');
}
else{
alert('The value changed!!');
}
}