3 ms·
You don't. The closure ends, the stack is popped, `a` is disposed, and then, in another closure, you have this line: const a = 1; `a` was never re-assigne
by aylmao 7y ago
You don't. The closure ends, the stack is popped, `a` is disposed, and then, in another closure, you have this line:
const a = 1;
`a` was never re-assigned, but the value of the variable we call `a` changed. I think the key here is knowing that if you have the following:
function Foo() {
const [a, setA] = useState(0);
return <span>{a}</span>
}
`Foo()` will be called on every render, `useState` will only use its argument the first time it's called (and then after that just remember its value), and `a` will be a "new `a`" every time, after which, like all variables declared in a function, it's discarded when the function returns.