Data Type in JS

M2-R5.1 · Chapter 6: JavaScript and Angular JS · 2 min read

Data types in JavaScript

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

  • Primitive data type
  • Non-primitive (reference) data type

Primitive data type-

There are five types of primitive data types in JavaScript. They are as follows:

Non- Primitive data type-
The non-primitive data types are as follows:

Coding for data types-


<script>
// Primitive Data Types
// Number
Let number = 42;
Document.write(“Number: “ + number + “<br>”);
// String
Let str = “Hello, world!”;
Document.write(“String: “ + str+ “<br>”);
// Boolean
Let bool = true;
Document.write(“Boolean: “ + bool + “<br>”);
// Undefined
Let u;
Document.write(“Undefined: “ + u+ “<br>”);
// Null
Let nullVar = null;
Document.write(“Null: “ + nullVar + “<br>”);
// Non primitive data Types
// Object
Let object = {
Name: “Aditya”,
Age: 24
};
Document.write(“Object: “ + JSON.stringify(object) + “<br>”);
// Array
Let array = [1, 2, 3, 4, 5];
Document.write(“Array: “ + array + “<br>”);
</script>