In the “Closures and Scope” section, just before the exercises, there is an example that doesn’t work for me.
Function countingFunction() {
var counter = 0;
final incrementCounter = () {
counter += 1;
return counter;
};
return incrementCounter;
}
When I run:
final counter1 = countingFunction();
final counter2 = countingFunction();
print(counter1()); // 1
print(counter2()); // 1
print(counter1()); // 2
print(counter1()); // 3
print(counter2()); // 2
I get the following notification:
2 Closure: () => int
Any ideas? I tried a few things but couldn’t get it sorted.