# JavaScript : Data Types

### What are data types?

The data types are just categorizations of data into different types depending upon various use cases. Javascript categorizes data into two types.

1. Primitive - Immutable values
    
    * number
        
    * string
        
    * boolean
        
    * bigInt
        
    * null
        
    * undefined
        
    * symbol
        
2. Object - Anything which is not primitive.
    

### Number

Integers or floating point numbers. In JavaScript, primarily they are defined using [Number Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#numeric_literals).

Examples: `123`, `12.3`

**Note:** BigInt is an extension of the Number data type with high precision.

### String

Text data. In JavaScript, strings are primarily defined using [String Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#string_literals).

Examples: `"Hello"` `'Hello'`

### Boolean

Logical values - `True` or `False` also called [Boolean Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#boolean_literals). Booleans are usually used in combination with control statements like if-else, for loop, switch etc.

### Null and Undefined

These are special values used in different use cases. The most common use case is to use them as a pre-initialized value for a variable.

`null` indicates the absence of an object value, which could be defined later.

`undefined` indicates the absence of a primitive value, which could be defined later.

### Object

Objects are mutable, unlike primitive values. We define an object in the form of key & value pairs. Each pair is called a property. Where a property key could be any valid JavaScript [identifier](https://developer.mozilla.org/en-US/docs/Glossary/Identifier). A property value could be any valid JavaScript datatype including objects.

Example

```javascript
{
    key1:"Hello"  //string as value
    key2:123      //number as value
    key3:true     //boolean as value
    key4:{ }      //object as value
}
```

Property value could be a function also ( in JavaScript functions are callable objects), we call them methods.

```javascript
{
    firstName:"Subham",                       
    lastName:"Sahu",
    getFullName: function () {                // method
        return this.firstName + this.lastName;
    }    
}
```

### For you to explore.

Learn about,

1. **symbol** data type.
    
2. [typeof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) Operator.
    

### What Next?

* What are other ways to define each data type?
    
* Can we convert one data type to another?
