In this tutorial, we will learn how to write a function in JavaScript. It will provide JavaScript eval() function. We learn how to write program in javascript by using java eval() function.
Take JavaScript eval() function to write a program in javascript.
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JavaScript program using eval() function</title> <script> var a = 10, b = 20, c = 30, sum, sub ,div; sum = eval("a + b + c"); sub = eval("a - b"); div = eval("a/b"); document.write(sum + "<br>"); document.write(sub + "<br>"); document.write(div); </script> </head> <body> </body> </html>
Output:
60 -10 1/2