Javascript Data Types

Every programming language has its own specific data types for assigning different kinds of data to a variable. Data types may vary from language to language.

For example, for showing a message to the users use string data type. For calculating use number or integer data type etc.

Javascript Data Types

In Javascript, there is a total of eight kinds of data types you will find. And they can be categorized into two supercategories. They are primitive data type and object data type.

Primitive Data Types

Primitive data types are immutable that means the value cannot be altered. Unlike object data, primitive data has no methods. Some primitive data types are:


Numbers are plain integer used in Javascript to calculate any arithmetic or any types of arithmetical calculation. Numbers are a common feature of any modern programming language.

Javascript Data Types - PrograCoding

Numbers can be pure integer or decimal – also known as floating point numbers. In general, numbers are assigned to a variable, or used in the comparison.


//numbers in variable
var num1 = 34;
var num2 = 45.36;

//numbers in comparison
if (age < 18) {  //here 18 is obviously a number
  warning = "You are not adult.";

In Javascript, we don't need to declare the data type while declaring a number based variable. Javascript interpreter understands itself which kinds of data are storing.

Unlike string data, we don't need to put single or double quotation for declaring numbers.


When you want to display some written information to the users using Javascript then string data type can help you to do that.


var text1 = "Hello, ";
var text2 = "PrograCoding!";
var text3 = text1 + text2;
console.log( text3 );


Hello, PrograCoding!

Note: You must have to write text inside a single or double quotation.


Like all the other programming languages, Boolean represent true and false for determining a logical execution. We will learn about the boolean operation in details in a later chapter.

For demonstration purpose let's see an example:


> Boolean(10 > 9)
> true

> Boolean(56 > 102)
> false

Undefined Data Type

When there is no value defined in a variable then if you call the variable to be executed then undefined will be returned.


var myMessage;
console.log( myMessage );



Null Data Type

When you will find something in a list like an array or object. Then if the thing does not exist in that list then it will execute null.

We will learn more about Null and Undefined data types after learning Array and Object in the later chapters.

Object Data Type

Unlike primitive data types, object data types are not immutable. Its data can be altered. Another difference between primitive and object, the object has methods but primitive has no method.

The object is a huge concept in Javascript. We will focus on Object in the later chapters.

We will learn all the data types in details and their methods in subsequent chapters.

« Previous Next »

Posted in