didn't mention closure scope, it allows you to have private member variables in javascript: const Counter = () => { let count = 0; return { incrementCount: () => count++, getCount: () => count } } const counter = Counter(); console.log(counter.getCount()); // 0 counter.incrementCount(); console.log(counter.getCount()); // 1 the count member variable of the function Counter is not accessible outside of the function scope, but it's value is still kept in memory because the object returned from counter still references it, and is the only way to access count. The garbage collector does NOT free resources that are still referenced. proper OOP hehe
didn't mention closure scope, it allows you to have private member variables in javascript:
const Counter = () => {
let count = 0;
return {
incrementCount: () => count++,
getCount: () => count
}
}
const counter = Counter();
console.log(counter.getCount()); // 0
counter.incrementCount();
console.log(counter.getCount()); // 1
the count member variable of the function Counter is not accessible outside of the function scope, but it's value is still kept in memory because the object returned from counter still references it, and is the only way to access count. The garbage collector does NOT free resources that are still referenced. proper OOP hehe