Enough JavaScript to get you Started : #4 Data Types and Variables
Tags: javascript, node, webdev, 100daysofcode
Published: 2021-01-09 06:28:59

### Variables? What is it?

👉 Variables are container that holds particular value for entire program execution cycle.

👉 Doesn't make any sense?

👉 Here's an example : in one of the previous blogs we thought of making a simple calculator where user can give 3 inputs like 'number 1' , 'number 2' , 'operation'.

👉 Now we need those inputs in our program every now and then...

👉 Either you can memorize your inputs😂(very unprofessional) or store it somewhere 

👉 Now we have only one option , that is to store our input data into some containers

👉 In the coding world we call these containers variables . Variables are nothing but a container which stores values and reduces your work.

<hr>
### How can i write a variable ?

**Example**

```
var userName = "Adarsh";
``` 
**Hey what's this ?**

👉 Now let's break this down 

👉 We've written `var userName = "Adarsh"`

👉 In JS `var` is reserved keyword , which can not be modified , on the other side var is used for declaring a variable in our program.

👉 `userName` is variable name , when you store some value in container you need to name the container to recall it later on in program, this can be anything

👉 Variable names are also known as identifiers !

👉 Rules for writing a identifier
      - identifiers can not contain white spaces 
      - `var user name` ❌
      - `var userName` ✅

      - identifiers can not contain special characters except `_` and `$`
      - `var user%name` ❌
      - `var ^username` ❌
      - `var user;name` ❌
      - `var user_Name` ✅

👉 `=` is also known as assignment operator , as the name suggests it is used to assign value to the variables.

<hr>

### JavaScript Data Types

👉 Data Types simply define what type of value is going to be stored inside our variable 

👉 **Example :** in terms of calculator we've got 3 inputs so we need 3 variables , 2 number types (num1 and num2) and 1 for operator (text or string)

### JavaScript : A loosely typed language 

👉 Hey, do i have to specify data types when declaring a variable ? so , the answer is no because JS is **loosely typed language** ! 

👉 JavaScript is a loosely typed language, meaning you don’t have to specify what type of information will be stored in a variable in advance. JavaScript automatically types a variable based on what kind of information you assign to it 

👉**Example**
```
var numOne = 5    // automatically assigns type `number`
var numTwo = 10  // automatically assigns type `number`
var Operator = "+"// automatically assigns type `string`
```

<hr>
### Data Types Available in JS 


![Artboard – 3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1609907232120/AYPiI3sE-.png)

**Primitive Data types :** Primitive or primary data type simply means a data type which is given by programming language , you don't have to specify it.

**Composite Data Types :** as the name suggests composite data types are made up by collection of Primitive Data types.

### Simple Data types 

👉 Number : used for storing numbers 

👉 String : used for storing text or sequence of characters

👉 Boolean : 1 bit data type which stores only `True` or `False`

👉 Null : null is assigned value which is empty or nothing

👉 Undefined : declared variable but not defined

_Don't worry if you don't get any of these , you'll understand all of these as an when we write a program :p_


<p>Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) <br>
<br>
Keep Coding ❤
</p>

#### Hey , Let' Connect👋
 [Twitter](https://twitter.com/codarsh) /
 [Github](https://github.com/WhoAdarshPandya/)