I'm currently working on a site that accepts user input via ACE editor in javascript and evaluates it and displays the output in another code editor.
The problem I have is, that I can't use eval to work properly. For example, if I get the following user input:
var i = 0;
I can call eval on the submitted String and the return value is undefined. Why don't I get 0, as the last evaluated statement should be i = 0? Another example: If I instead get the user input:
var i = 0;
console.log(i);
I still have an undefined return value, although I get the proper console log in my Browser console. If the user instead types in:
i = 0;
everything works perfectly fine, the return value is zero and eval works. Is there a possibility to use eval so that it evaluates the complete code submitted like if someone would type these lines one by one into the console and get the outputs?
Thanks for any help,
rikojir