JSFiddle - React, Tailwind, and code Playground

HTML

<button id="button">one</button>
<button id="button2">two</button>

JavaScript

button = document.getElementById("button");
button2 = document.getElementById("button2");


var x = 5;

(function(xRightNow) {
    button.onclick = function() {
        alert(xRightNow);
    }
})(x);

var x = 10;

button2.onclick = function() {
    alert(x);
}