Skip to content
Advertisement

Why the initial value did not change?

Help please, why the initial value did not change? *For some reason if I remove clock “else” everything works fine.

JavaScript

Advertisement

Answer

Due to hoisting, the var moves the declaration to the top of the function. So instead of value being the reference to the global, it is now scoped to your function. So your code actually looks like this:

JavaScript

To solve it, you need to get rid of the var inside your function.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement