JSFiddle - React, Tailwind, and code Playground
JavaScript
function f() {
function g() { console.log(x); }
let x = 0;
g(); // prints 0
x = 1;
g(); // prints 1
x = 3;
return g;
}
let x=4;
g = f();
g(); // prints 1
function f() {
function g() { console.log(x); }
let x = 0;
g(); // prints 0
x = 1;
g(); // prints 1
x = 3;
return g;
}
let x=4;
g = f();
g(); // prints 1