---
title: "What is the difference between let and const in Rust?"  
description: "What is the difference between let and const in Rust?"  
author: "Revati S Misra"  
published: 2023-06-19  
updated: 2023-06-20  
canonical: https://www.mindstick.com/forum/158778/what-is-the-difference-between-let-and-const-in-rust  
category: "rust"  
tags: ["programs", "rust"]  
reading_time: 2 minutes  

---

# What is the difference between let and const in Rust?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between let and [const](https://www.mindstick.com/forum/105419/what-is-the-difference-between-read-only-and-const-keyword) in [Rust](https://www.mindstick.com/forum/160170/explain-rust-s-ownership-borrowing-and-lifetimes-system)?

## Replies

### Reply by Aryan Kumar

The let and const keywords in Rust are used to declare variables. However, there are some key differences between the two keywords.

- **Scope:** let variables are scoped to the block in which they are declared, while const variables are scoped to the entire module in which they are declared.
- **Mutability:** let variables are mutable by default, while const variables are immutable.
- **Initialization:** let variables can be initialized with any expression, while const variables must be initialized with a constant expression.

Here is a table that summarizes the differences between let and const:

| Feature | let | const |
| --- | --- | --- |
| Scope | Block | Module |
| Mutability | Mutable | Immutable |
| Initialization | Any expression | Constant expression |

Here is an example of how to use let and const:

Rust

```plaintext
fn main() {
  // `let` variable.
  let x = 5;

  // `const` variable.
  const Y: i32 = 10;

  // The `x` variable can be mutated.
  x = 10;

  // The `Y` variable cannot be mutated.
  // Y = 20; // This will compile an error.
}
```

In this example, the x variable is declared using the let keyword and initialized with the value 5. The Y variable is declared using the const keyword and initialized with the value 10. The x variable can be mutated, while the Y variable cannot be mutated.


---

Original Source: https://www.mindstick.com/forum/158778/what-is-the-difference-between-let-and-const-in-rust

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
