data types in javascript

Posted on

Programming languages ​​all have built-in data types, but these often differ from language to language. This article attempts to list the built-in data structures available in JavaScript and their properties.

In this article, you will learn about the different data types available in JavaScript using examples.

JavaScript provides different data types to hold different types of values. There are two kinds of data types in JavaScript.

  1. Primitive data type.
  2. Non-primitive data type (reference).
  1. Primitive data type.
    • The JavaScript language provides 6 primitive data types:
      • Indefinite
      • Bad
      • Number
      • String of characters
      • boolean
      • Symbol

A variable that has no value assigned has the value undefined.

var language; //variable declared but not defined.
console.log(language); // Output: undefined

A variable was defined with a bad assess. It’s like indefinite. It’s storing nothing.

You can assign null to a variable to indicate that currently this variable has no value but will have one later. A null means the absence of a value.

var language = null; //It holds null value
var lang; // It holds undefined value

console.log(language == lang); // it return true, value is same of language and lang but data type different
console.log(language === lang); // it is return false, value is same of language and lang but data type different

There is only one type of number. There is no specific type for integers. Number is a primitive data type used for positive or negative integer, float, binary, octal, hexadecimal, and exponential values ​​in JavaScript

String of characters:

A string in JavaScript is a sequence of characters. It is textual content. It can be created using single or double quotes.

var str1 = "Hello, World!";
var str2 = 'Hi, Welcome to JavaScript Tutorial';

It is a logical entity. A variable can have two values true Where false.

var isActive = true;
var isDisabled = false;

New in ECMAScript6. A symbol is a unique and immutable identifier.

var x = Symbol();
var y = Symbol(10);
var z = Symbol('Hello');

2. Non-primitive data type (reference).

Non-primitive data types are called reference type because they refer to objects. ‘Object’ is a non-primitive data type in JavaScript. Arrays and functions in JavaScript belong to the ‘object’ data type.


An object in JavaScript contains key-value pairs in its address. When we refer to obj1, we are actually referring to the address in memory that contains the value {a:5,b:6}, instead of the value {a:5,b:6} directly.

var obj1 = { a: 5, b: 6 };

We can change or mutate the value of obj1.

obj1[a] =7;
console.log(obj1) // will return the value {a: 7, b: 6}

Using an array, we can store multiple items under one name.

// Call it with no arguments
var a = new Array();

// Call it with single numeric argument
var b = new Array(10);

// Explicitly specify two or
// more array elements
var d = new Array(1, 2, 3, "Hello");

Find all dates between two dates in JavaScript. Different ways to remove an element from an array in JavaScript.

Leave a Reply

Your email address will not be published.