Table of contents
Introduction
There are two types of Data Types available in JavaScript:
Primitive Data Type
Non-Primitive Data Type
Primitive Data Types
Primitive Data Type refers to the Data Type in which data doesn't contain any object or method. For example- Number, String, Boolean, Symbol, Null, etc.
- String: It refers to the sequence of characters that are present inside single or double quotes. For example-
var str1 = 'This is String 2';
var str2 = "This is String 1";
- Number: It represents data in numerical form. For example-
var a = 100;
var b = 20.1;
- Boolean: It represents a statement either as
false
ortrue
. For example-
var x = 12;
var y = 12;
var z = 13;
console.log(x == y); //gives output as true
console.log(y == z); //gives output as false
- Undefined: It is used when the user wants to declare a variable but doesn't want to assign any value to it. For example-
var a; //method 1
var b = undefined; //method 2
- Null: It represents an invalid value. For example-
var value = null;
Non-Primitive Data Types
Non-Primitive Data Type refers to the Data Type which can store multiple and complex values.
- Object: It is used for storing a collection of data items. For example-
var obj1 = {
a: 10, //stores data in Number
b: 'Hi!', //stores data in String
c: function(){
return 'This is a JavaScript Object';
}
}
- Array: It is used for storing multiple Data Items under a single variable name. For example-
var arr = ['Hi',21,3.2,false];
I hope that you must have found this article quite helpful. If yes, then do give a read to some of my other articles!
Who knows you might become a great programmer ๐ค!
ย