Eval ():- JavaScript





  • The eval() method is used to convert string to JavaScript expression, variable, statement, or sequence of statements.
  • If the argument is an expression, eval() evaluates the expression.
  • If the argument is one or more JavaScript statements, eval() executes the statements.

  • Code:-



  • <!DOCTYPE html> 

    1. <html> 
    2.  
    3. <head> 
    4.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    5. </head> 
    6.  
    7. <body> 
    8.  
    9.  <h1>eval</h1> 
    10.  
    11.  <button onclick="getval();">Access eval</button> 
    12.  
    13.  <script> 
    14.   /* Evaluate/Execute JavaScript code/expressions 
    15.           Convert String to JavaScript expression, variable, statement, or sequence of statements. */ 
    16.   function getval() 
    17.   { 
    18.    var test = "a"; 
    19.    var a = "Anjali"; 
    20.  
    21.    alert("test : " + test); 
    22.    alert("eval(test) : " + eval(test)); 
    23.   } 
    24.  </script> 
    25.  
    26. </body> 
    27.  
    28. </html>
    Eval ():- JavaScript Eval ():- JavaScript Reviewed by Network security on November 13, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.