Learn JavaScript

JavaScript Datatype

A datatype is the most fundamental characteristic of any programming language. It is nothing but a set of values that can be manipulated in a programming language. In this tutorial we will be focusing to learn some JavaScript datatypes, those are frequently occurred in a JavaScript program / code. There are two types of datatypes in JavaScript programming language:

  • Primitive Datatype.
  • Non – Primitive Datatype.

Primitive Datatype: Primitive datatype includes the datatypes such as: String, Number, Boolean, Null, and Undefined.

Non – Primitive Datatype: It includes the datatypes such as: Object, Array, and RegExp.

JavaScript String Datatype

JavaScript string data type is used to store the string data (text message) within the single quotes (‘Hello World’), double quotes (“Hello World”), and back ticks (`Hello World`).


var name = 'Ravi';
var subject = "Programming";
var intro = `He is ${name} and he is learning ${subject}`;

Note: Practically, single quotes and double quotes are same and we can use either of them. On the other hand, the back ticks are generally used when we have to insert some sort of variables or expressions into a string. It can be done by using the following syntax ${variable name or expression}, as we have done in above example.

JavaScript Number Datatype

JavaScript Number Datatype is an integer, floating point number which includes exponential and decimal point numbers. +infinity, -infinity, and NaN (Not a Number) is also included in JavaScript Number Datatype. The Number datatype lies in the range (-253 – 1, 253 – 1). However ,if we need to manipulate a number which lies outside of this range, then we can use the BigInt datatype.


var num1 = 2;
var num2 = 2.456;
var num3 = 2e7;    // it is treated as 2 * 10^7
var num4 = 2/0;
console.log(num4); // infinity
var num5 = -2/0;
console.log(num5); // -infinity
var num6 = "ab"/5;
console.log(num6); // NaN (a string can not be divided by a number)

Note: BigInt is introduced in the latest version of JavaScript and is not supported by many browsers like: Safari.

JavaScript Boolean Datatype

This is a logical datatype that presents only two truth values true and false.


var dataChecked = true;
var valCounted = false;

Note: The complete discussion of Boolean will be done in JavaScript Logical Operator topic.

JavaScript Null Datatype

In JavaScript programming language null is an special data type, which is used to represent an unknown or empty value.


var num = null; // num variable is empty

Note: since JavaScript is a case sensitive programming language, hence null, Null, and NULL all different.

JavaScript Undefined Datatype

JavaScript undefined datatype is used to represent the value of a variable whose value is not assigned. for example: if a variable is declared but the value of that variable is not assigned, then the value of that variable will automatically be assigned to undefined. JavaScript also allows us to explicitly assign the undefined as the value to a variable.


var v;
console.log(v); // undefined
var a = undefined;
console.log(a); // undefined

Note: For better JavaScript programming practice, it is recommended not to explicitly assign undefined to a variable. Basically, null is used to represent an unknown or empty value.

JavaScript Object Datatype

JavaScript Null Datatype is one of the most complex and structured data type. JavaScript allows us to store a collection of different data or data types in a single object.


const student = {
name: "Ravi",
class: 12,
subject: "JavaScript Programming Language"

JavaScript Program to declare and display the content of an Object.

<h2>Learning JavaScript Object datatype</h>
<p id="jod"></p>
// creating an object
const student = {
name: "Ravi",
class: 12,
subject: "JavaScript Programming Language"
// displaying the content of the object
document.getElementById("jod").innerHTML = student.name + " studies in " + student.class + " loves " + student.subject;


Learning JavaScript Object datatype

Ravi studies in 12 loves JavaScript Programming Language


This JavaScript tutorial is designed to help the beginners as well as the professional developers. For better understanding the language of the tutorial is kept simple and easy to understand.


This tutorial demands to have the basic knowledge of the programming languages such as c or c++, HTML for the better understanding of the JavaScript programming language. The other basic requirement to learn JavaScript through this tutorial is the basic knowledge of computer and information technology so you can easily acquire a better understanding JavaScript programming.

Community Helping

In case you find any kind of error like typing error, spelling mistakes, incorrect grammar, incorrect information or any other mistakes. Please feel free to write to us at: akyadav@etutororg.com.