cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
636 stars 100 forks source link

Clarify the scope of "let" in section 3.1. Variables and Mutability #215

Open Marc-C-Anderson opened 1 month ago

Marc-C-Anderson commented 1 month ago

URL to the section(s) of the book with this problem:

https://rust-book.cs.brown.edu/ch03-01-variables-and-mutability.html

Description of the problem:

There is a clear mention of the scope for "const" There is no clear discussion about the scope of "let"

The response to Q1 could be implied but I got it wrong the first time based on the chapter content. My background is from C, C++, Java, javascript which all allow non-const global variables.

Question 1 Which of the following statements is correct about the difference between using let and const to declare a variable? The response "const can be used in the global scope, and let can only be used in a function"

Suggested fix:

Perhaps add clarification about the scope of "let" to the section. I didn't get it from the chapter text.