I'm not sure if I phrased the question accurately, but up to this point I had always assumed a function declaration in javascript was 'set in stone'.
When I tried to better understand closures (mimicking a simplified version of React's useState), I became unsure of where the 'x' in the following code block was being stored in memory:
function useState () {
let x = 0;
return [function() { console.log(x) },function (y) { x = y}];
}
const [getX, setX] = useState();
getX()
setX(1)
getX()
So while the useState function returns a getter and a setter as variables "getX" and "setX", where exactly is "x" being stored? In the original declaration of useState? What am I missing here?