JavaScript 中的 eval() 函数
htmljavascriptprogramming scripts
eval() 函数接受一个包含 JavaScript 代码的字符串值。此函数执行给定的代码并返回代码的结果。
语法
其语法如下
eval(32*45);
示例
<html> <head> <title>JavaScript 示例</title> </head> <body> <script type="text/javascript"> document.write(eval(32*45)); document.write("<br>"); document.write(eval(new String("Hello welcome to Tutorialspoint"))); </script> </body> </html>
输出
1440 Hello welcome to Tutorialspoint