JavaScript eval() function
The JavaScript eval function is a very powerful function. The eval function can perform the operation of a certain string (String). If the string is an expression, eval will calculate the result of the operation. If it is just a connection of a number of strings, eval It will automatically return the group and the entire string. Although the JavaScript eval function is very powerful, it seems that there are not many opportunities to use in-depth powerful functions.
Basic syntax of JavaScript eval function
JavaScript eval function example
var a=2,b=4,c=6;
var B = eval('A'+a+'=b*c');
document.write(B+'<br>'); // 輸出 24
document.write(A2); // 輸出 24
--></script>
In the example, we first declare three JavaScript variables , namely a, b, and c, which are all positive integer variables, and then declare a variable B to use eval to calculate the string, and then we list the parameters through document.write What will be printed on the screen? The answer is two 24s. Let’s take a look at the string in the eval function first. The meaning can be seen as the result of "A2=24", so the result of the first output of variable B is 24, and the second output of A2 is also eval The function may get an integer value of 24, so the result is the same whether it outputs B or A2.
Run the while loop in eval
Post a Comment
0 Comments