mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-02 12:03:49 -05:00
fix(curriculum): Clarify understand-string-immutability (#47448)
* Clarify understand-string-immutability Remove some misleading explanation (immutability is orthogonal to literals). * Remove extraneous whitespace Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org> * Improve explanation per review suggestion Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org> Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org>
This commit is contained in:
@@ -11,14 +11,14 @@ dashedName: understand-string-immutability
|
||||
|
||||
In JavaScript, `String` values are <dfn>immutable</dfn>, which means that they cannot be altered once created.
|
||||
|
||||
For example, the following code:
|
||||
For example, the following code will produce an error because the letter `B` in the string `Bob` cannot be changed to the letter `J`:
|
||||
|
||||
```js
|
||||
let myStr = "Bob";
|
||||
myStr[0] = "J";
|
||||
```
|
||||
|
||||
cannot change the value of `myStr` to `Job`, because the contents of `myStr` cannot be altered. Note that this does *not* mean that `myStr` cannot be changed, just that the individual characters of a <dfn>string literal</dfn> cannot be changed. The only way to change `myStr` would be to assign it with a new string, like this:
|
||||
Note that this does *not* mean that `myStr` could not be re-assigned. The only way to change `myStr` would be to assign it with a new value, like this:
|
||||
|
||||
```js
|
||||
let myStr = "Bob";
|
||||
|
||||
Reference in New Issue
Block a user