Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • 2
    The declaration of the IIFE (Immediately Invoked Function Expression) returns another function. So the initial run of the IIFE creates the counter variable and returns a function that does work on the counter variable. So when you call add() you are not running the var counter = 0 code, you're running the return of the IIFE (which happens to be a function). Commented Jun 17, 2014 at 20:54
  • counter += 1 can be ++counter. Commented Jun 17, 2014 at 21:05