Are You Still Confuse with Data Types in JavaScript ?

Open Source 22 Mar , 2013  


In my previous post I’ve described that how you can be away from bugs , But without knowing about the datatypes correctly you will fall in error most probably, and messages like Undefined Variable will always be stick to you… Today I’ll describe what are the basics of Data Types in JavaScript, Have a look at following picture showing the hierarchy of Datatypes-


String :

A string can be any text inside quotes. You can use single or double quotes, and Sometimes you may need to save quotation marks which you used to create boundary of, so you can use escape character to use of quotation mark. have a look over following example :

// Strings can be created with double or single quotes.
var a = "See I am in Double Quotes";
var b = 'And now in single';

var statement1 = 'we say "JavaScript is awesome!"';
var statement2 = "we say \"JavaScript is awesome!\"";

Number :

Number types may have both positive or negative value. There is no difference between integer and floating point values in JavaScript..

// Numbers are any whole or floating point integer.

var number1 = 100;
var number2 = 100.10;

Boolean :

Boolean types are either true or false, you can declare it as follows 

// Example of Boolean values.
var okay = true;
var fail = false;

null and undefined :

null and undefined are special types in JavaScript. Null types are such values that represent the absence of a value which is same as  many other languages. Where Undefined types represent a state in which no value has been assigned at all. This type is created in two ways: by using the undefined keyword or by not defining a value at all.

// Define a null value.
var new_var = null;

// Two ways to achieve an undefined value.
var my_var = undefined;
var my_new_var;

DID YOU KNOW :  JavaScript variables are all objects. When you declare a variable you create a new object?



Now, It is considered that everything else in JavaScript is an Object. While there are numerous built-in objects, But I’m Explaining most popular of them here :

In my next Posts I’ll explain about the Objects, Array and Functions,  Stay Tuned and Have look over my next release to know more about Objects…

, , , , , , , ,