JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="code">alert("foo")</textarea><button onclick="test()">Test</button>

JavaScript

try{
    eval('foo =1; (function(){alert("test")})();');
} catch (e) {
    alert(e);
}

window.test  = function(str){
    eval(document.getElementById("code").value); 
}