JSFiddle - React, Tailwind, and code Playground
by bouillard
HTML
<div id="wo">without var</div>
<div id="with">with var</div>
JavaScript
x=1;
$('#wo').click(function() {
a = x++;
setTimeout(function() {
alert(a);
},1000);
});
$('#with').click(function() {
var a = x++;
setTimeout(function() {
alert(a);
},1000);
});