Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Introduction to JavaScript Data Types

This article will cover the JavaScript Datatypes. It will demonstrate the functionality by giving some examples and play with String, Number and Boolean Data Types.

Introduction:

In this tutorial you will learn about JavaScript data types, which is one of the most fundamental characteristics of a programming language. Basically data types are the type of values that can be represented and manipulated in a programming language. JavaScript will allow you to work with three main primitive data types, Number String and Boolean, First of all lets go through the concept of primitive data types then will go further.

Primitive data types are predefined by the language and named by a keyword .This chapter will cover three primitive data types separately and one more trivial data type Null or Undefined.

Number Data Type:

All numbers in JavaScript are represented as floating point values, but they may or may not have a fractional component. If they have a decimal point or fractional, they are represented by using the 64-bit floating-point format defined by the IEEE standard. If they don’t have a decimal point or fractional they are treated as integers-base-10 whole numbers in a range of -253 to 253.

Example:

 var numerical_value=222;.

Following example will show you the simple manipulation of number data types.

Listing 1: Script of Number Data type in JavaScript.

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Data Types</title>
</head>
<body>
<script>
var negativeNumber = -1000;
var zero = 0;
var fourDigits = 2534;
var someFloat = 0.3555
var anotherNumber = 144.006;
var negDecimal = -2.3;
var lastNum = 19.5e-2 
var zeroDecimal = 12.0;
var x=((-1000+0+2534+0.3555+144.006-2.3+19.5e-2+12)/22)*19.5e-2;
document.write(negativeNumber + "<br>");
document.write(zero + "<br>");
document.write(fourDigits + "<br>");
document.write(someFloat + "<br>");
document.write(anotherNumber+ "<br>");
document.write(negDecimal + "<br>");
document.write(lastNum + "<br>");
document.write(zeroDecimal + "<br>");
document.write(x + "<br>");


</script>
</body>
</html>
Above figure is output of number data types and a simple mathematical calculation over the values stored by variable

Figure 1: Above figure is output of number data types and a simple mathematical calculation over the values stored by variable.

Boolean Data Type:

In this category of JavaScript data type variable holds only two value true or false .This value is result of any logical comparison in your script that returns the True/False or Yes/No value .”Such as (X==Y)”. This statement manipulates that the variable value of X is equal to Y or not, if yes then it will print true/yes otherwise false/no. In digital computation you don’t need to do anything extra, JavaScript will automatically convert true to 1 and false to 0.

Variable declaration is done like this

Var female= “false” 
Var male=”true ” Following script will compile the idea of Boolean data type in JavaScript  

Listing 2: Script to demonstrate JavaScript Boolean Data Types

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Data Types</title>
</head>
<body>
<script language="javascript">
var value1 = true;
var value2 = false;


if(value2 == false)
{
document.write("variable Value2 is satisfying the the logical comparison so printed value is :TRUE");
}
</script>
 </body>
</html>
Above figure is output of Boolean data type script in which value2 is printing its true comparison value

Figure 2: Above figure is output of Boolean data type script in which value2 is printing its true comparison value.

String Data Type:

A string is used to represent normally text that is sequence of valid characters within a given character group. It always defined by enclosing single or double quotes. Sometimes it happens that you want to put some characters in a string may not exist on the keyboard, or may be special characters that can't appear as themselves in a string. For that case you need to use an escape sequence to represent the character. An escape sequence is a character or numeric value representing a character that is followed by a backslash ( \ ) to indicate that it is a special character.

Example:

var numeric_value="122" ;
var string1="india" Following script will clear the concept how to use your string data type in JavaScript ;

Listing 3: Script to demonstrate JavaScript String Data Types

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Data Types</title>
</head>
<body>
<script language="javascript">
var string1="My name is jack";
var string2='1333';
var string3='!@#$%^*()';
var string4='122.34568';
var string5='ABCDEFGH';
var string6='';
var string7="this is special string which is not available in keyboard \"Γεια σου τι κάνεις\"";
document.write(string1 + "<br>")
document.write(string2 + "<br>")
document.write(string3 + "<br>")
document.write(string4 + "<br>")
document.write(string5 + "<br>")
document.write(string6 + "<br>")
document.write(string7 + "<br>")
</script>
</body>
</html>
Above figure is output of string data type in which stored value in variable are printed on output screen

Figure 3: Above figure is output of string data type in which stored value in variable are printed on output screen.

Null or Undefined Data Types:

Java script has two more literals; null and undefined, that is considered to be objects. Value null means that it does not have any valid object, string, number or Boolean value. Basically we can say that It is the value of no value. Normally you assign the value null to something when you want it to have a valid but non-existent value.

An undefined variable is one that has been named, but does not have a value assigned to it. In case of undefined, first of all we should know that undefined is not keyword. It is a predefined global variable, but it is treated like any other variable. Be careful not to overwrite it. The variable undefined is used to store the value of an undefined variable.

Example:

var Var1=null;
var Var2=null;

Conclusion:

This tutorial covered the basic concept related to data types in JavaScript. This area is very broad, So I suggest that go through the basics and then try for some advance functionality. Please post your questions at mrbool site and we will get back to you.



I am Software Developer from India. I hold B.Tech. in Computer Science & Engineering. I am having 2+ years experience of developing Web applications and Websites using HTML, JavaScript, CSS, C#.NET etc..

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login