JavaScript Data Types || Simple introduction to JavaScript Data Types

We stored different types of values in javascript variables. The data that we stored in JavaScript variables can be any type of data. Data types are used to identify the data type of stored value in variables.


JavaScript Data Types in Simple Words

JavaScript data types are the basic and important concepts in JavaScript. In every programming interview, you must hear the questions about javascript data types.


Before learning javascript data types, you need to know what a javascript variable is and the types of javascript variables. What is JavaScript? JavaScript Types.


If you already know about javascript variables you must need to know how to use javascript variables in a project. To use the javascript variables correctly in your project you must need to have a high knowledge of JavaScipt Data Types.


So in this article, I will simply describe JavaScript data types. Read this article till the end if you want high knowledge about javascript data types.

What is JavaScript Data Types?

JavaScript data types are the values that we store in JavaScript variables. There are up to five types of data types that we stored in javascript variables.


There are main two types of javascript variables:

  1. JavaScript Permitive Data Type
  2. JavaScript Non-Primitive Data Type/ Reference Data Type

1.    Primitive Data Type

JavaScript primitive data type is a type of data that stores the value of a variable in a stack-type memory. Stack-type memory means the variable value is stored as temporary memory.


There further six types of javascript primitive data types. Below is a list of primitive data types.

  • String
  • Number
  • Boolean
  • Null
  • Unidentified
String:    If the value is written between the double quotes("value"), we consider the javascript value to be string-type data. Whether it is single quotes('value') or double quotes("value"), still the value is string type data. 
If the value of the variable is a number or a single character and is written in quotes, then the value is also considered as string-type data.

var VariableName = "String";

Number:    If the javascript variable value looks like a number or without single quotes and double quotes then we consider the value of the javascript to be a number. 

var VariableName = 123; 

Boolean:     Boolean data types have two types of variable values either the variable value is true or the variable value is false. There are only two possible conditions in the boolean data type(true or false). The bollen variable values are also written without any quotes.

var VariableName = true; 

Null:    Null is a unique and sensitive keyword in JavaScript. There is no actual value of the Null keyword in JavaScript. If we write the value of the javascript variable as Null, then the value is considered as Null type data.

 var VariableName =  Null;

Unidentified:    If we create a variable in javascript but we did not declare any value if those created variables then it is considered as unidentified, for example;

 var VariableName;

2.    Non-Primitive Data Type

JavaScript primitive data type is a type of data that stores the value of a variable in a heap-type memory. Heep-type memory means the variable value is stored as dynamic memory.

 

There are further two types of non-primitive data types. Below is a list of primitive data types.

  • Array
  • Object

Array:     If the multiple string type value is written between the square bracket [], then the value of the javascript variable is an array.

var VariableName = ["value1",  "value2", "value3",  ];

Object:    If the variable values are written between curly brackets{}, also create a submenu or subcategory between the curly braces, then the variable value is an Object type.

 var VariableName = { subcategory: "value"  };

Post a Comment

Previous Post Next Post