JSFiddle - React, Tailwind, and code Playground
HTML
<div class="output">Here's the output:<ol></ol></div>
JavaScript
var x = "Global scope";
var y = "Not changed.";
function Foo() {
this.x = "Attribute of foo";
var x = "In foo's closure";
y = "Changed!"
this.getX = function () {
return x;
}
}
function log(astr) {
$("div.output ol").append("<li>"+astr+"</li>");
}
// do some logging
log(x); // "Global scope"
log(y); // "Not changed"
foo = new Foo();
log(y); // "Changed!"
log(foo.x); // "Attribute of foo"
log(x); // "Global scope"
log(foo.getX()); // "In foo's closure"