JSFiddle - React, Tailwind, and code Playground

JavaScript

var i = 1;
var fn = (function(x){ // this is a self-executing anonymous function
    return function() { // this closure maintains a reference to x
        alert(x); 
    };
})(i); // we're passing i by value into another closure
i = 10; // when we change i here, it has no affect on x
fn.call(); // this will alert 1