How to display JavaScript variable value in alert box?


To display JavaScript variable value in an alert box, try to run the following code −

Example

Live Demo

<html>
   <head>
      <script>
         function display() {
            var a = "Simple";
            var b = "Learning";
            alert(a +" Easy "+ b);
         }
      </script>
   </head>
   <body>
      <input type="button" value="Click me!" onClick="display();">
   </body>
</html>

varma
varma

e

Updated on: 16-Jun-2020

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements