I thought that I understand closures, but this example made me confused.
function f() {
let x = 1;
const g = () => {
console.log(x);
}
x = 100;
g();
}
f()
I think that the result should be 1, but it is 100.
I thought that g in the moment of a declaration should take x that exists in the outer scope.
But it took x value after reassignment.
Why is it working like this?