Various data types in JavaScript

Sourav.Kayal
Posted by in JavaScript category on for Beginner level | Points: 250 | Views : 1752 red flag

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. 
Page copy protected against web site content infringement by Copyscape

About the Author

Sourav.Kayal
Full Name: Sourav Kayal
Member Level: Silver
Member Status: Member,MVP
Member Since: 6/20/2013 2:09:01 AM
Country: India
Read my blog here http://ctrlcvprogrammer.blogspot.in/
http://www.dotnetfunda.com
I am .NET developer working for HelixDNA Technologies,Bangalore in healthcare domain. Like to learn new technology and programming language. Currently working in ASP.NET ,C# and other microsoft technologies.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)