---
title: "Creating variable in java script"  
description: "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 jav"  
author: "Anonymous User"  
published: 2011-03-10  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/488/creating-variable-in-java-script  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# Creating variable in java script

In this demonstration we learn how to create a [variable](https://www.mindstick.com/blog/11493/what-is-a-variable) in [java](https://www.mindstick.com/interview/22908/what-are-java-string-class-method) [script](https://www.mindstick.com/interview/2280/is-jquery-replacement-of-java-script). We know that variable is a [location](https://www.mindstick.com/news/2574/twitter-conveniently-reveals-a-location-sharing-policy-amid-elonjet-controversy) in [memory](https://yourviews.mindstick.com/story/1186/ayurvedic-tips-for-the-mind-and-memory) which [stores](https://www.mindstick.com/forum/161350/how-does-sqlite-database-stores-tables) some [values](https://www.mindstick.com/forum/159360/how-to-write-sql-query-to-join-comma-separated-values). In java script we create any type of variable by using “**[var](https://www.mindstick.com/forum/33920/what-is-different-var-and-dynamic-types-in-c-sharp)”** keyword. The [data](https://www.mindstick.com/articles/326933/5-reasons-big-data-is-important-to-the-logistics-industry) 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](https://www.mindstick.com/mindstickarticle/e2d167d6-541f-4551-b260-90058aee8587/images/bcbff7ba-552c-47c7-979d-7155949765ee.png)

\

---

Original Source: https://www.mindstick.com/articles/488/creating-variable-in-java-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
