Data types in JavaScript
JavaScript is dynamic typed languages. It means we don’t have to define a definite data type for a variable we can store any kind of data in variables and the data type is defined is on the fly by the JavaScript engine.
01. undefined
When the name of a variable is declared and not assigned a value the variable remain undefined and the data type of undefined is undefined.
02. Boolean (true or false)
Boolean type is used when an expression has value of true or false. They are boolean data type.
03. Number
Number is a data type to define number. Number are used for doing various mathematical operations. There are two types of number one is integer and another one is float .
The integer is the number without any fraction(11, 12, 123) and the float is the fractional number(1.3, 2.333).
The largest number supported by JavaScript number type is (2⁵³–1).
Example : 1,0.1,3.333 etc.
04. String
Strings are another kind of data which represents character or simply sequence of some characters. It could be a single letter or a word or a sentence.
05. BigInt
BigInt is a data type to declare number larger than (2⁵³-1)
BigInt is created by appending “n” after a number or by calling the BigInt() function.
06. Symbol
Symbol is data type which create unique data every time. Symbol is created by calling Symbol() function
When Symbol() is called is crates new Symbol each time.
const sym1 = Symbol(“4”)
const sym2 = Symbol(“4”)
Though sym1 and sym2 has same value but they are diffrent
sym1===sym2
This will return false
07. Object
Object is a collection of property with key value pair. In JavaScript almost every thing is an object.
08. Array
Array is another kind of data type where we can store more than one variable . This is another kind of object. The property of an array can be accessed by their index. Indexes are usually starts from 0.
09. Function
Function is an block of code which performs a particular tasks . A function performs that action when it called for. Function is another kind of objects .
10. null
In JavaScript null means nothing. It simply means not existence of a value . The data type for null is object.
11. NaN(not a number)
NaN means not a number. If we try to perform a mathematical operation with a not numbered value NaN returned by the JavaScript engine. The data type for NaN is number