---
title: "What is the difference between var, let, and const in JavaScript? When would you use each one?"  
description: "What is the difference between var, let, and const in JavaScript? When would you use each one?"  
author: "Revati S Misra"  
published: 2023-04-14  
updated: 2023-04-17  
canonical: https://www.mindstick.com/forum/157812/what-is-the-difference-between-var-let-and-const-in-javascript-when-would-you-use-each-one  
category: "javascript"  
tags: ["javascript", "javascript object"]  
reading_time: 1 minute  

---

# What is the difference between var, let, and const in JavaScript? When would you use each one?

What is the [difference between var, let, and const](https://www.mindstick.com/forum/161265/what-is-the-difference-between-var-let-and-const) in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)? When would you use each one?

## Replies

### Reply by Aryan Kumar

In JavaScript, **[var](https://www.mindstick.com/forum/33920/what-is-different-var-and-dynamic-types-in-c-sharp)**, **let**, and **[const](https://www.mindstick.com/forum/105419/what-is-the-difference-between-read-only-and-const-keyword)** are used to declare variables, but they differ in terms of scope and mutability.\
\
If a variable is declared with **var** outside of a function, it becomes a global variable and is accessible throughout the entire script\
\
**let** or **const** are only accessible within the block in which they are declared. Variables declared with **let** can be updated within their scope, but cannot be re-declared. Variables declared with **const.**\
\
Use **var** if you need to declare a variable that is accessible within a function or throughout the entire script and you need to update or re-declare it within its scope.

Use **let** if you need to declare a variable that is only accessible within a block and you need to update it within its scope.

Use **const** if you need to declare a variable that is only accessible within a block and its value will not change after it is initialized.


---

Original Source: https://www.mindstick.com/forum/157812/what-is-the-difference-between-var-let-and-const-in-javascript-when-would-you-use-each-one

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
