From 8cf36fb2e8809f7668796f8e1895b5432975e224 Mon Sep 17 00:00:00 2001 From: Hiroshi Yoshioka <40815708+hyoshioka0128@users.noreply.github.com> Date: Tue, 16 Jun 2026 00:30:39 +0900 Subject: [PATCH] Fix formatting and clarify const variable behavior Correct formatting issues in code blocks and explanations regarding constant variables. https://github.com/microsoft/Web-Dev-For-Beginners/blob/main/2-js-basics/1-data-types/README.md #PingMSFTDocs --- 2-js-basics/1-data-types/README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/2-js-basics/1-data-types/README.md b/2-js-basics/1-data-types/README.md index 68dcdc37f5..8efa5a2f1b 100644 --- a/2-js-basics/1-data-types/README.md +++ b/2-js-basics/1-data-types/README.md @@ -144,7 +144,7 @@ Creating and **declaring** a variable has the following syntax **[keyword] [name - When would you choose `let` over `const` for a variable? ```mermaid -stateDiagram-v2 +  stateDiagram-v2 [*] --> Declared: let myVar Declared --> Assigned: myVar = 123 Assigned --> Reassigned: myVar = 456 @@ -188,10 +188,10 @@ Constants have two main rules: **Simple value** - The following is NOT allowed: - ```javascript + ```javascript const PI = 3; PI = 4; // not allowed - ``` + ``` **What you need to remember:** - **Attempts** to reassign a constant will cause an error @@ -200,10 +200,10 @@ Constants have two main rules: **Object reference is protected** - The following is NOT allowed: - ```javascript + ```javascript const obj = { a: 3 }; obj = { b: 5 } // not allowed - ``` + ``` **Understanding these concepts:** - **Prevents** replacing the entire object with a new one @@ -212,15 +212,15 @@ Constants have two main rules: **Object value is not protected** - The following IS allowed: - ```javascript + ```javascript const obj = { a: 3 }; obj.a = 5; // allowed - ``` + ``` - **Breaking down what happens here:** - - **Modifies** the property value inside the object - - **Keeps** the same object reference - - **Demonstrates** that object contents can change while the reference stays constant + **Breaking down what happens here:** + - **Modifies** the property value inside the object + - **Keeps** the same object reference + - **Demonstrates** that object contents can change while the reference stays constant > Note, a `const` means the reference is protected from reassignment. The value is not _immutable_ though and can change, especially if it's a complex construct like an object.