All Data Types in JavaScript
Tags: javascript, beginners, webdev
Published: 2021-11-09 19:40:09

If you are a beginner in web development then you must learn the JavaScript. It powers the interactions on each and every webpages. Basically it enables the websites to interact with the user in many ways like music player, alert, pop-ups or a video player or animations.

But to create such interactions on the websites developers need to write the code that take user inputs or call an [api](https://www.howtogeek.com/343877/what-is-an-api/) to get any data, but to do all this things we need some type of storage container that will store different types of data like numbers, strings, objects or boolean. So each programming languages defines some data types to sort the things out.

The JavaScript is a *"dynamically typed"* language, we not have to specify the data types at variable declaration unlike C/C++ or Java. Variables can store any data type in it. There are total 8 data types in JavaScript. These are as follows-
1. Number
2. String
3. BigInt
4. Boolean
5. Null
6. Undefined
7. Object
8. Symbol

## Number
Numbers as the name suggest, it used to store numbers. Numbers can be integers, fractions, or Infinity/-Infinity and NaN(Not a Number).

Example-
```javascript
let int = 123; // integer
let fraction = 1.2 // fraction
let infinity = Infinity // Infinity
let notANumber = 0/0 // NaN
```

## String
String is the type of data in which, there is a bunch of alphanumeric characters and other symbols are together. In other words, it is a group of characters. Strings are to be surrounded by quotes, single or double. 

Example-
```javascript
let str = "abc123,./"; 
// string can have alphanumeric and other symbols
alert( `The back-tics can used to use variables in in between the string like str is- ${str}!` ); 
// The back-tics can used to use variables in in between the string like str is- abc123,./ 
```

## BigInt
BigInt is made to accommodate really large numbers which are more than 2^53 -1 or less -(2^53 -1) due to its technical limitations. They are represented by appending 'n' after the number.

Example-
```javascript
let bigint = 123456789123456789123456789n;
```

## Boolean
Boolean is used to represent true or false values. Sometimes we only two values for our function or we have to check some condition that is true or false.
Boolean values can also come as a result of comparision. 

Example-
```javascript
let isTrueOrFalse = true;
let firstIsGreaterOrNot = 7 > 9;
console.log(firstIsGreaterOrNot); // false
```

## Null
People often confused between null value and undefined value(non existing value). Null values represents "nothing", "empty" or "unknown".

Example-
```javascript
let value = null;
console.log(value); // null
```

## Undefined
They are different then Null data types. They represents that the variable is not assigned any value.

Example-
```javascript
let name;
console.log(name); // undefined
```

## Object
Objects are non primitive data type. We can defined key-value pairs. We can store any type values in one such object. We can store collections of data of different data types.

Example-
```javascript
let obj = 
{
 name: Nirbhay,
 age: 19,
 isIndian: true
}
```

## Symbol
Symbol are used to create unique identifiers for objects. They can used to generate unique identifiers.

No example for this because i have to read more on it.

*This post is based on what I learned about data types in JavaScript from [javascript.info.](https://javascript.info/types) It is basically a summary of that article. Visit it to get some deeper understanding.*

cover photo by [Pankaj Patel](https://unsplash.com/@pankajpatel?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/code?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)