Skip to content

Instantly share code, notes, and snippets.

@saqibameen
Created July 27, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqibameen/0304958010244a2f47ebf537ec4e3e05 to your computer and use it in GitHub Desktop.
Save saqibameen/0304958010244a2f47ebf537ec4e3e05 to your computer and use it in GitHub Desktop.
Convert a string into a an actual JavaScript expression/statement
// Source: https://stackoverflow.com/questions/55074927/eval-vs-function-constructor
(() => {
let secret = 42;
eval("console.log(secret)"); // 42
let fn = new Function("console.log(secret)");
fn(); // secret is not defined
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment