Introduction
A data type in JavaScript is a container that stores a specific type of data. In this article, we learn about various data types in JavaScript and how to work with them.
Here's a brief overview of the main data types in JavaScript:
- Number: This data type is used to represent numerical values. Numbers can be integers (whole numbers) or floating-point numbers (decimal numbers).
- String: This data type is used to represent textual data. Strings are sequences of characters enclosed in quotes (either single or double).
- Boolean: This data type is used to represent logical values. Boolean values can be either true or false.
- Undefined: This data type represents a variable that has not been assigned a value.
- Null: This data type represents a deliberate absence of any object value.
- Object: This data type represents complex data structures, including arrays, functions, and objects.
- Symbol: This data type represents unique values that can be used as object keys.
JavaScript is dynamic like any other programming language, so you don't need to declare the variable type. If I am talking about C, C++, C#, Java, etc., you must define the datatype when you declare the variable. But The left-side variable takes on the data type of whatever value you gave the right-hand side.
Data type in JavaScript
The data type is a primary data type that can be used in a program. JavaScript provides different data types to hold different types of values. There is no need to specify the variable type because the JavaScript Engine dynamically uses it. The different types of data types in JavaScript are shown in the flowchart below,

There are two significant data types in JavaScript,
- Primitive data types in JavaScript
- Non-primitive data types/ composite data types in JavaScript
Primitive Data Types in JavaScript
- Number represents a numeric Value.
- String is a sequence of Characters.
- Boolean represents Boolean value, either True or False.
- Undefined represents an undefined value.
- Null represents no value.
Note. Data types in JavaScript can be defined at run-time.
Number data type in JavaScript
The number datatype represents the numeric value; the number type represents integer, float, or decimal. It can hold any value. You need to use var here to specify the datatype. Suppose I declared a variable.
Var x=10;
And after that, I assign a string value like this x=" sagar" so you will know the data types are changed at run-time.
For example, you can assign values like 10,10.2, which means even if you assign a floating-point number to a variable, it is treated like several data types.
Code Example
<!DOCTYPE html>
<html>
<head>
<title>Java Script</title>
</head>
<body>
<h4>JavaScript</h4>
<p id="p1"></p>
<p id="p2"></p>
<p id="p3"></p>
<script>
var a =100; //integer
var b =10.5; //float
var c =24.00; //decimal
document.getElementById("p1").innerHTML = a;
document.getElementById("p2").innerHTML = b;
document.getElementById("p3").innerHTML = c;
</script>
</body>
</html>
Output

String data type in JavaScript
The string is a sequence of characters; the character must represent in single ('')or double quotations ("") in JavaScript. You can assign a single character or multiple characters in JavaScript String.
For example, "Hello"," 'Hello World'
Example





Pratik PatelPosted Mar 30, 2023, 8:59 AM
I just love the way you explain everything about JavaScript Data Type
Naveenkumar ParamasivamPosted Mar 25, 2020, 2:08 PM
Nice article in javascript