DEV Community

Cover image for JavaScript with Run Options
Mafee7
Mafee7

Posted on

JavaScript with Run Options

Run Code In JavaScript With options like:

  • Use Unchangeable variables:
var options = {
  UseConstants: "true"
}
var JavaScriptCode = `
var js = "JavaScript";
console.log(js);
js = "wow";
// Cannot Change Value
` // JavaScript Code That will be affected with options

if(options.UseConstants){
    var u = URL.createObjectURL(new Blob([JavaScriptCode.replaceAll("var", "const")], {type: "application/javascript"}));

    var script = document.createElement("script");
    document.head.appendChild(script);
    script.src = u;
    script.defer = "";
}

// Gives Error: Assignment to constant variable.
/*
Code After Change:
const js = "JavaScript";
console.log(js);
js = "wow";
// Cannot Change Value
*/

Enter fullscreen mode Exit fullscreen mode

Top comments (0)