JavaScript: Why does closure only happen if I assign the return function to a variable?

_counter is the local variable within function counter(). Every time when you call counter() a new _counter will be created.

But var createClosure = counter() only called the function 1 time, that’s why _counter is not newly created every time and ‘remembered’ there (that’s where closure happens)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)