There is a counter made as an example in w3c schools website right here http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_settimeout_cleartimeout2
var c = 0;
var t;
var timer_is_on = 0;
function timedCount() {
document.getElementById("txt").value = c;
c = c + 1;
t = setTimeout(function(){timedCount()}, 1000);
}
function startCount() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
clearTimeout(t);
timer_is_on = 0;
}
I don't understand the startCount function. I don't understand for what purposes it is written and I can't translate it into 'human' language, so I could understand it.
An if statement runs if it is true, right ? It checks if !timer_is_on is true and than executes the code. But what does (!timer_is_on) mean ? Is zero converted to false and then the ! converts it to true ? Or does it say if 'not 0' than... But than it won't execute because there is no else{} and var timer_is_on is always = 0.