Quick warning
This is hard
Closures
A closure is a function that has access to the parent scope, even after the parent function has closed. JS will automatically store the state of a closure in the heap memory, even after the parent function has returned. This behavior makes them useful for encapsulating private variables.
function encapsulatedState(x) {
let state = 10;
return function() {
state += x;
return state;
}
}