cover-img

Data types in JavaScript

Exploring primitive data types

27 August, 2022

0

0

0

As the name suggests in this piece we are going to discuss different data types in JavaScript.
JavaScript is a loosely typed language i.e. variables can be declared anywhere for example within a loop or conditional statements. It must also be noted that variables are dynamic in nature i.e. the type of data stored in them can also be changed. Please look at the code below
Before we take a deep dive into different data types it is important to mention that in this article we are only going to discuss primitive data types i.e. data types which are building blocks of other data types (ex: Objects).
In JavaScript there are seven types of primitive data types:

1.

Boolean

2.

Null

3.

Undefined

4.

Number

5.

BigInt

6.

String

7.

Symbol
Before proceeding further it is important to know about the typeof operator. Data type of a variable can be checked by using the typeof operator as shown in the code below
The above code will give the following output

Boolean

Boolean type variables can only store boolean values i.e. true and false. See the code below for better understanding.
The above code will result in the following output

String

String type variables store textual data for example, a single character or a complete sentence.
The output of the above code will be as follows

Undefined

A variable that has not been assigned a value is of type undefined.

Null

A variable is of type null if it has been intentionally left blank.
There is difference between null and undefined. A variable is of type null if its value has been intentionally left blank where as variable is of type undefined if its value has not yet been defined.

Null datatype cannot be identified using typeof operator. If a variable containing a null value is passed to a typeof operator it will return object as output.

The output of the above code is given below

Symbol

To understand symbols you will need better understanding of the concepts of immutability in Javascript. I will explain this concept in more details in a follow up article for the time being you just need to understand that symbol data types are immutable and unique.

Number

Number type variables can store double precision floating point numbers in the range of -2^1024 to 2^1024. All the floating point number greater then -(2^-1074) and less then 2^{-1074} are converted to 0. All the negative floating point integers less then -2^{1024} are converted to negative infinity and all the numbers greater then 2^1024 are converted to positive infinity.
Also it must be noted that numbers data type can store integers in the range of -2^53 -1 and 2^53 -1.
img

If you want to check which if a value can be stored as a number data type, the following refrences could be useful:

  • Number.MAX_SAFE_INTEGER is the the largest integer value that number can store
  • Number.MIN_SAFE_INTEGER is the smallest integer that number can store.
  • Number.MAX_VALUE is the largest positive floating point value that number can store.
  • Number.MIN_VALUE is the smallest floating point value that number can store.
  • - Number.MIN_VALUE is the largest negative floating point value that number can store.
  • - Number.MAX_VALUE is the smallest negative floating point value that number can store.

BigInt

BigInt is used to used to store integers which are outside the limit of number data type. Any integer can be converted to a bigInt by using the suffix n. See code below for better understanding.
when the above code is run the output will be the following

0

0

0

Divyansh Chahar
Loading Full Stack Developer ............

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2025. Showcase Creators Inc. All rights reserved.