---
title: "JavaScript Datatypes"
url: https://khanwaseem.com/blog/course/javascript-datatypes
author: "khan Waseem"
published: 2023-09-26
updated: 2023-09-26
topics: ["course", "Javascript Tutorial"]
description: "Learn about JavaScript data types, including numbers, strings, booleans, arrays, objects, and more, with clear examples for each type"
---

# JavaScript Datatypes

In JavaScript, data types define the kind of values that variables can hold and how those values behave. Understanding data types is fundamental to working with JavaScript effectively.

Table of Contents

[Toggle](#)

- [1. Number:](#1-number)
- [2. String:](#2-string)
- [3. Boolean:](#3-boolean)
- [4. Array:](#4-array)
- [5. Object:](#5-object)
- [6. Null:](#6-null)
- [7. Undefined:](#7-undefined)
- [8. Function:](#8-function)
- [9. Symbol:](#9-symbol)
- [10. BigInt:](#10-bigint)

## 1. Number :

This data type is used for numeric values, which can be integers or floating-point numbers (decimals).

**Example : **

```javascript
let age = 25;
let price = 9.99;
Code language: JavaScript (javascript)
```

## 2. String :

Strings are used to represent text. You can enclose text in single (‘ ‘), double (” “), or backticks (```) quotes.

**Example : **

```javascript
let greeting = "Hello, world!";
let name = 'Alice';
Code language: JavaScript (javascript)
```

## 3. Boolean :

Boolean data types have only two possible values: `true` or `false`. They are used for logical operations and comparisons.

**Example : **

```javascript
let isStudent = true;
let isLoggedIn = false;Code language: JavaScript (javascript)
```

## 4. Array :

Arrays are used to store collections of data, such as a list of numbers or strings. Elements in an array are accessed by their position (index) in the array.

**Example : **

```javascript
let fruits = ["apple", "banana", "orange"];Code language: JavaScript (javascript)
```

## 5. Object :

Objects are used to store key-value pairs, allowing you to create more complex data structures.

**Example : **

```javascript
let person = {
    name: "John",
    age: 30,
    isStudent: false
};Code language: JavaScript (javascript)
```

## 6. Null :

The `null` data type represents the intentional absence of any object value. It’s often used to initialize variables that will hold an object later.

**Example : **

```javascript
let emptyValue = null;
Code language: JavaScript (javascript)
```

## 7. Undefined :

When a variable is declared but hasn’t been assigned a value, it has the `undefined` data type. It’s different from `null` in that it indicates a variable’s uninitialized state.

**Example : **

```javascript
let jobTitle;
console.log(jobTitle); // Outputs "undefined"
Code language: JavaScript (javascript)
```

## 8. Function :

Functions are a special data type in JavaScript, representing executable code blocks. You can declare functions and call them to perform specific tasks.

**Exmaple : **

```javascript
function add(x, y) {
    return x + y;
}
Code language: JavaScript (javascript)
```

## 9. Symbol :

Symbols are unique and immutable values often used as object property keys to avoid naming conflicts.

**Example : **

```javascript
const uniqueKey = Symbol('unique');
let user = {
    name: "Alice",
    [uniqueKey]: 12345
};
Code language: JavaScript (javascript)
```

## 10. BigInt :

The `BigInt` data type is used for large integers that cannot be represented accurately with the standard `Number` data type. It’s denoted by appending `n` to a numeric literal like `10n`.

**Example : **

```javascript
const bigNumber = 1234567890123456789012345678901234567890n;Code language: JavaScript (javascript)
```

Understanding these data types helps us work with different kinds of information in our JavaScript programs. It’s essential to choose the appropriate data type for each variable or value to ensure our code behaves as intended. JavaScript’s dynamic typing allows variables to change data types during runtime, so it’s crucial to be aware of how data types behave in various contexts.

### Related posts:

[JavaScript -Boolean](https://blog.khanwaseem.com/javascript-boolean/)
[JavaScript – Operators](https://blog.khanwaseem.com/javascript-operators/)
[JavaScript – Arrays](https://blog.khanwaseem.com/javascript-arrays/)
[JavaScript – Variables](https://blog.khanwaseem.com/javascript-variables/)

Powered by [YARPP](https://yarpp.com).
