# Js Data Types

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7wvg9q8h1i4x3ly6rng.png align="left")

Datatypes are of two types:-

1.Primitive Datatype

2.Non-Primitive Datatype

# **1\. PRIMITIVE DATATYPE**

Primitive Datatypes specify mainly the sizes and shapes of the variable values. There are 8 primitive datatypes namely:-char, byte, Boolean, int, long, float, short, double.

### **A. Boolean Type Datatype:-**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739297178653/345a0c14-231e-4ee9-b4e0-ba451b31d502.png align="center")

### **\*\*\*OTHER PRIMITIVE DATATYPES IN A CODE SNIPPET :-**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739297994583/86c71448-f2f8-4d96-82f9-864b85b1931b.png align="center")

# **2.NON PRIMITIVE DATATYPES:-**

Non-Primitive Datatypes are the reference type of data. They are the derived datatypes. They contain collection of datatypes . Object and Array are the two important this type of datatype.

\*\*\*YOU ALL KNOW ABOUT THE OBJECT AND ARRAY .WE WILL GO THROUGH THIS TOPIC.\*\*\*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739298658334/a3218a66-e0a9-405b-818d-bc58f4ab3fb0.png align="center")

## **CONVERSION OF DATATYPES:-**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739458753027/fb850f10-19d0-46b1-8592-404d71efa0bd.png align="center")

### **IMPLICIT CONVERSION**

Implicit Conversion is also known as “TYPE COERCION“. Implicit Conversion is defined as the datatype in which one datatype is converted into another type of datatype without the use of explicit instructions. Mainly, these implicit instructions are seen in the mathematical operations and string concatenations.

## **THE TYPES OF IMPLICIT CONVERSION ARE:-**

### <mark>1. Implicit Conversion to String</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739460530654/03fa5447-3fee-47d1-af3c-9f24407e609d.png align="center")

### **<mark>2. Implicit Conversion to Number</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739465490066/ada0e65a-fcb8-41ba-9fe0-b61ab92f572c.png align="center")

### **<mark>3. Implicit Conversion in Comparisons</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739465678683/c1345497-0798-46cb-afea-9b905bd6a906.png align="center")

**<mark>Note:</mark>** <mark> Using </mark> `==` <mark> allows type coercion, but </mark> `===` <mark> (strict comparison) does </mark> **<mark>not</mark>** <mark> perform implicit conversion.</mark>

### **SUMMARY TABLE:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739465910359/6d94b0dd-9544-4134-ae4b-acbedfad5146.png align="center")

## **EXPLICIT CONVERSION:-**

Explicit Conversion is also known as “Typecasting”. Explicit Conversion is defined as the process in which one data type is converted into the another data type manually.

## **THE TYPES OF EXPLICIT CONVERSIONS**

## **<mark>1. Convert to String</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739469853518/886f5b12-70a9-4311-b67f-e5d27df5e6a7.png align="center")

## **<mark>2. Convert to Number</mark>**

We can convert strings or Booleans to numbers using:

A. Number(value).

B. Parse Int(value) for Integers.

C. Parse Float(value) for decimals.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739471026578/338edd7b-a52a-40be-a7eb-0ce6aef06f52.png align="center")

## <mark>3. Convert to Boolean</mark>

Boolean(value).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739471734808/797c0a8d-8c16-4a9b-bd51-ecdacf5f0a7a.png align="center")

## **<mark>4. Convert to Object</mark>**

JSON. parse() is used to convert the code into object. Use JSON. parse() to convert Json strings into object.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739473331036/9d015b36-4bda-43ff-8b89-1e101ef59ce5.png align="center")

### <mark>SUMMARY TABLE:</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1739473426705/47a05df7-46e2-4af1-b1db-7bb0b6ebd754.png align="center")
