This commit is contained in:
Ilya Kantor 2017-03-21 14:41:49 +03:00
parent 4ae129054e
commit ab9ab64bd5
476 changed files with 3370 additions and 532 deletions

View file

@ -0,0 +1,31 @@
importance: 5
---
# Are counters independent?
Here we make two counters: `counter` and `counter2` using the same `makeCounter` function.
Are they independent? What is the second counter going to show? `0,1` or `2,3` or something else?
```js
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
alert( counter() ); // 0
alert( counter() ); // 1
*!*
alert( counter2() ); // ?
alert( counter2() ); // ?
*/!*
```