Home > DeveloperSection > Articles > Creating variable in java script

Creating variable in java script


JavaScript JavaScript 
Ratings:
0 Comment(s)
 3515  View(s)
Rate this:

Creating variable in java script

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="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <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 />");

        }

    </script>

</head>

<body onload="variableDemo()">

 

</body>

</html>

Output of the following code snippet is as follows

Creating variable in java script

 


Don't want to miss updates? Please click the below button!

Follow MindStick