How to get console.log output from eval()?
问题 I am using eval() to run a script from a string. Below is the code: eval('console.log("hello")'); I will get hello from the console output. I wonder whether I can save the hello into an variable in the current context. So I am looking for something like this: const output = eval('console.log("hello")'); // I expect the console output is returned from eval() function. But I get an undefined response. Is there a way for me to do that? 回答1: It is impossible because console.log() only returns