Skip to content
Advertisement

reassign global boolean from a function

i am trying to reassign the value of these booleans from inside of a function and use the reassigned values inside of another function. how do i do that?

JavaScript

Advertisement

Answer

In general, you should avoid trying to do this, as it can make your code harder to understand and debug (see action at a distance).

But, if you’re really sure you want to do this, you need to use the global keyword to tell the interpreter that you’re reassigning to the boolean variables defined outside of the function rather than creating fresh variables:

JavaScript
Advertisement