Created
July 27, 2020 14:13
-
-
Save saqibameen/0304958010244a2f47ebf537ec4e3e05 to your computer and use it in GitHub Desktop.
Convert a string into a an actual JavaScript expression/statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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