Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,868 questions

51,791 answers

573 users

How to evaluates or execute JavaScript code represented as a argument string in JavaScript

9 Answers

0 votes
  <script type="text/JavaScript"> 
    
    var a = 100;
    var b = 1;

    document.write(eval("a + b + 99"));
    
    /*
    run
    
    200 
    
    */
  
  </script>

 



answered Jul 24, 2016 by avibootz
0 votes
  <script type="text/JavaScript"> 
    
    var c = "31";

    document.write(eval("c"));
    
    /*
    run
    
    31  
    
    */
  
  </script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var a = "2";
var b = "3";

document.write(eval("a * b"));

/*
run

6 

*/

</script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var a = "2";
var b = "3";
 
document.write(eval("7 * 7"));
 
/*
run
 
49  
 
*/

</script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var a = "2";
var b = "3";

document.write(eval("7 * b"));

/*
run

21   

*/

</script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var a = "2";
var b = "3";
 
document.write(eval(new String("3 + 5")));
 
/*
run
 
3 + 5   
 
*/

</script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var s = "if ( a ) { 2 + 2; } else { 3 + 3; }";
var a = true;

document.write(eval(s));
 
/*
run
 
4   
 
*/

</script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var a = 10;
var s = "if (a == 10) {x = 100;} else x = 0;";


document.write(eval(s));
 
/*
run
 
100   
 
*/

</script>

 



answered Jul 24, 2016 by avibootz
0 votes
<script type="text/JavaScript"> 

var a = 10;
var s = "if (a == 10) {document.write('a = 10 and '); x = 100;} else x = 0;";


document.write(eval(s));
 
/*
run
 
a = 10 and 100    
 
*/

</script>

 



answered Jul 24, 2016 by avibootz
...