In this demonstration we learn how to create a variable in java script. We know that variable is a location in memory which stores some values. In java script we create any type of variable by using “var” keyword. The data type of “var” is decided at run type on the basis of value. In this demonstration I had created several types of variable by using “var” keyword.

Write down following code snippet to perform this demonstration
<html xmlns="">
    <script type="text/javascript">
        function variableDemo() {
            //In this method we learn how to create variable in java script.
            var eid = "S0001";        //Creating an string type variable.
            var ename = "John Smith";      //Creating another string type variable.
            var eage = 25;          //Creating an integer type variable.
            var emarried = false;        //Creating an boolean type variable
            var esalary=2500.25;    //Creating a float type variable.
            //Writing values of the variable on browser by using document.write() method.
            document.writeln("Employee Id   :  " + eid + " <br />");
            document.writeln("Employee Name   :  " + ename + " <br />");
            document.writeln("Employee Age   :  " + eage + " <br />");
            document.writeln("Employee Married  :  " + emarried + " <br />");
            document.writeln("Employee Salary  :  " + esalary + " <br />");
<body onload="variableDemo()">
Output of the following code snippet is as follows

Creating variable in java script


  Modified On Mar-22-2018 07:10:00 AM

Leave Comment