eval 函数 代替函数_eval()函数以及JavaScript中的示例
eval 函數(shù) 代替函數(shù)
eval()函數(shù) (eval() function)
eval() function is a predefined global function in JavaScript and it is used to evaluate (execute) an expression, which is passed to the function as a parameter. It can also evaluate any JavaScript code.
eval()函數(shù)是JavaScript中預定義的全局函數(shù),用于評估(執(zhí)行)表達式,該表達式作為參數(shù)傳遞給該函數(shù)。 它還可以評估任何JavaScript代碼。
Syntax:
句法:
eval(expression);Here, expression is the JavaScript code or any expression having values or variables.
此處, 表達式是JavaScript代碼或具有值或變量的任何表達式。
Example:
例:
<html> <head> <title>JavaScipt Example</title> </head><body><script>var num1 = 100;var num2 = 200;var num3 = eval("num1 + num2"); //add num1 and num2var num4 = eval("num3 + 100"); //add num3 and 100var str = eval("num4.toString(16)"); //convert num4 value to hexdocument.write("num3: " + num3 + "<br>");document.write("num4: " + num4 + "<br>");document.write("str: " + str + "<br>");</script> </body> </html>Output
輸出量
num3: 300 num4: 400 str: 190翻譯自: https://www.includehelp.com/code-snippets/eval-function-with-example-in-javascript.aspx
eval 函數(shù) 代替函數(shù)
總結
以上是生活随笔為你收集整理的eval 函数 代替函数_eval()函数以及JavaScript中的示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《侍宴覆舟山诗》第三句是什么
- 下一篇: math.sqrt 有问题_JavaSc