Data-Types in JavaScript

Masum Billah
3 min readNov 3, 2020

Data types basically specify what kind of data can be stored and manipulated within a program. Basically, Javascript has two types of data-types.

  1. Primitive
  2. Object/ Function

Primitive Data Type:

Primitive data type data is saved in direct value. Without primitive data, all objects in javascript. Easy way to recognize primitive data as it has no prototypes in the browser console because primitive data direct save with value.

a) Number

All types of numbers are primitive in javascript like integer/float.

Example :

const number = 55;
const floatNumber = 55.55;

b) String

Everything inside a single(‘ ’) or double(“ ”) quote is considered as a string. It could be the number string or normal text string.

Example :

const strText = 'Hello Bangladesh';
const strNumber = '112233';

c) Boolean

Boolean data stored either logical true otherwise logical false. It must be a lowercase true and false character otherwise throw an error.

Example :

const isAccess = true;
const isStong = flase;

d) Undefined

When unintentionally we forget or missed sore data in a variable, it is stored is undefined.

Example :

const str;
console.log(str) //undefined

e) Null

Null is a special and interesting data type. When we intentionally ignore to store value in the variable, we write null place in the value.

Example :

const userData = null ;
console.log(userData); //null

Object/Function Data Type:

The object data does not directly save the value but its reference is saved. Javascript objects can be Function, Array, Object, Number’s Wrapper, String’s Wrapper, Date’s are also an object. The object has many own properly.

a) Function

A function is a callable object that executes a block of code. The function is a very important part of javascript. Functions are used so much in JavaScript that JavaScript is called functional programming.

Example :

function add(a,b){return a+b;
}
add(10,20) //30

b) Array

An array is a type of object used for storing multiple values in a single variable. The array is a very interesting and helpful part of our programming journey. We can access an array variable with an array index number.

Example :

const arr = ['Mango', 'Banana', 'Orange']
console.log(arr[1]) //'Banana'

c) Object

The object type is special. The object is a complex data type that allows storing collections of data. An object contains properties, defined as a key-value pair. An object key always a string but a value can be any type of data.

Example :

const obj = {
name: 'Billah',
address: 'Dhaka',
zip: 1100
}
console.log(obj.address) //'Dhaka'

d) Date

The date is also an object data type in javascript. It’s a very interesting topic. Date objects are created with the new date() constructor.

Example :

cosnt date = new Date();console.log(date)  //Tue Nov 03 2020 21:00:48 GMT+0600 (Bangladesh Standard Time)

d) Number and String Wrapper

The number and String constructor also is an object. Its own prototype.

Example :

const str = new String(string);

--

--