Do you know what will be the output of this code?
JavaScript
let x = 1;
const getX = () => x;
x = 2;
console.log(getX());
Show answer and explanation
The answer is 2.
A closure keeps a live reference to the variable, not a snapshot of its value. By the time getX() runs, x is 2.