JSFiddle - React, Tailwind, and code Playground

JavaScript

function testClosure(){
 var x = 2;
    return function(y){
        alert(eval(y));
    }
    
}

var closure = testClosure();

closure("x+2");