pull/1887/merge
Hiroshi Yoshioka 2 weeks ago committed by GitHub
commit 4cf54975a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -188,10 +188,10 @@ Constants have two main rules:
**Simple value** - The following is NOT allowed: **Simple value** - The following is NOT allowed:
```javascript ```javascript
const PI = 3; const PI = 3;
PI = 4; // not allowed PI = 4; // not allowed
``` ```
**What you need to remember:** **What you need to remember:**
- **Attempts** to reassign a constant will cause an error - **Attempts** to reassign a constant will cause an error
@ -199,11 +199,11 @@ Constants have two main rules:
- **Ensures** the value remains consistent throughout your program - **Ensures** the value remains consistent throughout your program
**Object reference is protected** - The following is NOT allowed: **Object reference is protected** - The following is NOT allowed:
```javascript ```javascript
const obj = { a: 3 }; const obj = { a: 3 };
obj = { b: 5 } // not allowed obj = { b: 5 } // not allowed
``` ```
**Understanding these concepts:** **Understanding these concepts:**
- **Prevents** replacing the entire object with a new one - **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: **Object value is not protected** - The following IS allowed:
```javascript ```javascript
const obj = { a: 3 }; const obj = { a: 3 };
obj.a = 5; // allowed obj.a = 5; // allowed
``` ```
**Breaking down what happens here:** **Breaking down what happens here:**
- **Modifies** the property value inside the object - **Modifies** the property value inside the object
- **Keeps** the same object reference - **Keeps** the same object reference
- **Demonstrates** that object contents can change while the reference stays constant - **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. > 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.

Loading…
Cancel
Save