In this article we will look into how to use var keyword in JavaScript
Various data types in
JavaScript
In this article we are going to discuss various data types of
JavaScript. JavaScript is a client side programming language and executes on
client’s browser.
Please keep in mind “Java and JavaScript are not same”.
Basically junior developer thinks that both are same, but there is huge different
between them.
Java is one platform and JavaScript is a light weight
programming language which runs on browser and immediately shows output. As
JavaScript is a programming language it has one common feature called data type
like other programming languages.
Here we will discuss various techniques to work with different
data in JavaScript.
First of all JavaScript is loosely type checking language, what
does it mean? It means there is no various data type in JavaScript. Then how we
will handle different data? Answer is - using var keyword.
Yes, var keyword supports all data type. In below example I have shown how to use var
keyword.
Uses of var keyword
<html>
<head>
</head>
<body>
<script>
var x =100;
document.write("Value of x with var data type "+ x);
</script>
</body>

Without var keyword
JavaScript is not only loosely type checking language but
also very programmer friendly. If you even forget to use var keyword then is no
error. In below example I did not use var keyword .
</html>
<html>
<head>
</head>
<body>
<script>
var x =100;
document.write("Value of x with var data type "+ x);
</script>
</body>
</html>

Various data with var
As I told earlier we can assign any data type to var. In
below example I have declared all variable as var type and assigned various
data type into them.
<html>
<head>
</head>
<body>
<script>
var integerNumber = 100;
var floatNumber = 10.10;
var StringData = "Sourav Kayal";
var Character = '@';
document.write("Value of integer number: " + integerNumber + "<br>");
document.write("Value of Float number: " + floatNumber + "<br>");
document.write("Value of String number: " + StringData + "<br>");
document.write("Value of Character number: " + Character + "<br>");
</script>
</body>
</html>

Array in JavaScript
Like other full fledge programming languages, JavaScript too
support array. Again we can use var keyword to define array. In below example, person array is defined and initialized with person name(String).
<html>
<head>
</head>
<body>
<script>
var person=new Array();
person[0]="sourav";
person[1]="Sathis";
person[2]="Nontey";
document.write("First Person is : "+ person[0]);
</script>
</body>
</html>
Conclusion :
In javaScript var keyword supports all different data. Hope this will help to understand basics of JavaScript's data type.