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:
```javascript
const PI = 3;
PI = 4; // not allowed
```
```javascript
const PI = 3;
PI = 4; // not allowed
```
**What you need to remember:**
- **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
**Object reference is protected** - The following is NOT allowed:
```javascript
const obj = { a: 3 };
obj = { b: 5 } // not allowed
```
```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
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
```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
> 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