Jump to content

if(!var_name)


alzami
 Share

Recommended Posts

whats happening is that the if() syntax is casting timer_is_on from a number to a boolean. any number other than 0 is considered true. the "!" is a not operator so when javascript sees "if(!timer_is_on)", its roughly translating to "if timer_is_on is NOT 0, then do this stuff"

 

its important that the function made that check so that it didn't make multiple setTimeout function calls. if it did then the id of the previous setTimeout would be lost, overwritten with the new setTimeout function. If that happened then there would be no way to use clearTimeout on the first setTimeout.

 

actually…. after calling stopCount, one of the setTimeouts would clear and then you would be able to stop the 2nd timeout after its made a count, however, that wouldn't be desired functionality and would be confusing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...