Data Types in JavaScript:

Variables in JavaScript can hold many data types. In any programming language data type is very important. JavaScript has dynamic types means a single variable can hold different type of data types.

For example:
var a;

var a=10;

var a = “Alex”;

Data Types in JavaScript:

Here is a list of data types which we can use in our JavaScript

  • Strings
  • Numbers
  • Booleans
  • Arrays
  • Objects
  • Undefined and Null
  • Typeof Operator

Strings in JavaScript:

You can declare a variable with string value. String is nothing but a series of characters like:”Mac Pascal”.

One thing you have to know that strings are always written in quotes. You can use single quote or double quote.


var name = “Charlie Toe”;   //string in double quotes

var name = ‘Charlie Toe’;   //string in single quotes


var name = “Charlie Toe’;

In above example we use both double quote and single quote so this is a wrong way to define string.

You can also use quotes inside quotes.

var x =”Happy B’day to You.”

var x = “It’s Ok buddy.”


Numbers in JavaScript:

There is only one type of number that JavaScript has or supports. You can also write numbers with decimal or without decimal.

var a = 240;             //without decimal

var b = 15.67;         //with decimal

If you want to write extra large or extra small numbers than you have to use scientific (exponential) notation.


var a= 345e5;          //34500000

var b = 123e-5;       //0.00123


With the help of following example you can under stand it easily

Booleans in JavaScript:

In any programming language Booleans have only two values “true” and “false”. Booleans are used for conditional testing of programme.

Values of Booleans other than “true” and “false” are

  • “On” and “Off”
  • “Yes” and “No”


Operators in Booleans:

                       Operator                         Description                          Example
                           ==                           Equal to                    If(name == John)
                            >                        Greater than                         If(age>30)
                            <                           Less than                    If(salary<40000)

 Arrays in JavaScript:

Arrays are also containers and use to store multiple values in a single variable. Arrays are always written in square brackets and the items of arrays will be separated by commas.

Arrays items are count by index and it will start from zero and than other numbers. Means the first item will be count as [0] and second will be [1] and so on.



In following example we are displaying two values of array

Objects in JavaScript:

We can say that object is a collection of properties. Property is combination of “name” and “values” and the pairs are separated by commas. To write objects in JavaScript you have to use curly braces.



In above example you can see that we use object name and than dot and than property name to fetch the property value of that object.

Undefined and Null in JavaScript:

In JavaScript Undefined means the variable is declared but not assigned by any value so the variable is called Undefined Variable.

The variable which assigned value by “null” is called null variable.

You can understand it better by the following example.


The typeof operator in JavaScript:

The typeof operator is used in JavaScript to find the data type of a variable such as whether a variable is a number, string, Booleans etc.



Leave a Reply

Your email address will not be published. Required fields are marked *