---
title: "How many type of variable in JS and what kind of use?"  
description: "How many type of variable in JS and what kind of use?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93729/how-many-type-of-variable-in-js-and-what-kind-of-use  
category: "web application"  
tags: ["web application development", "javascript", "web development"]  
reading_time: 2 minutes  

---

# How many type of variable in JS and what kind of use?

How many type of [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) in JS and what kind of use?

## Answers

### Answer by Ethan Karla

There are 3 ways to declare a JavaScript variable: 1. Using var 2. Using let 3. Using const **Using var** Variables are containers for storing data (values).In this example, x, y, and z, are variables, declared with the var keyword.

```
var x = 5;
var y = 6;
var z = x + y;
console.log('The value of z is: ' + z);
```

**Using let** Variables defined with let cannot be re-declared. Variables defined with let must be declared before use. Variables defined with let have Block Scope.

```
let x = 'MindStick pvt ltd';
let x = 0;
// SyntaxError: 'x' has already been declared
var x = 2;    // Allowed
let x = 3;    // Not allowed
{
let x = 2;    // Allowed
let x = 3     // Not allowed
}
{
let x = 2;    // Allowed
var x = 3     // Not allowed
}
```

**Using const** Variables defined with const cannot be re-declared. Variables defined with const cannot be re-assigned. Variables defined with const have block scope. Like fixed value.

```
const PI = 3.141592653589793;
PI = 3.14;      // This will give an error
PI = PI + 10;   // This will also give an error
```

\


---

Original Source: https://answers.mindstick.com/qa/93729/how-many-type-of-variable-in-js-and-what-kind-of-use

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
