I'm creating a custom JavaScript console that I expect to work exactly like the console in dev tools. (or … something like a REPL) https://github.com/MohammadMD1383/js-interactive
I get user inputs one by one and evaluate them. eval(userInput)
the problem is with defining variables. I noticed that the eval
function uses a new VM each time, so the declaration is in a separate VM than a call to the variable. so it causes the error someVarName is not defined
the sample of my code:
button.onclick = () => {
evaluateMyExpression(textarea.value);
};
function evaluateMyExpression(code) {
let result = eval(code);
// do something else …
}