O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

To implement this with a closure, we can reuse most of the code above. Watch and be amazed:

image with no caption

T

From

Cover of Head First JavaScript Programming

Note

If the increment of the global variables is causing confusion with the concept of pass-by-value, here is the help: Pass-by-value concept is manifested when a global variable is passed as an argument.