mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-05 00:00:18 -04:00
fix(curriculum): clarify that replace() returns a new string in JS lesson (#61730)
Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Co-authored-by: Ilenia M <nethleen@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ In JavaScript, there are many scenarios where you may need to replace a portion
|
||||
|
||||
For instance, you might need to update user information in a URL, change the formatting of dates, or correct errors in user-generated content.
|
||||
|
||||
The `replace()` method in JavaScript allows you to find a specified value (like a word or character) in a string and replace it with another value.
|
||||
The `replace()` method in JavaScript allows you to find a specified value (like a word or character) in a string and replace it with another value. The method returns a new string with the replacement and leaves the original unchanged because JavaScript strings are immutable.
|
||||
|
||||
Here is the basic syntax:
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ const text = "HELLO, WORLD!"
|
||||
console.log(text.toLowerCase()); // "hello, world!"
|
||||
```
|
||||
|
||||
- **The `replace()` Method**: This method is used to find a specified value (like a word or character) in a string and replace it with another value.
|
||||
- **The `replace()` Method**: This method allows you to find a specified value (like a word or character) in a string and replace it with another value. The method returns a new string with the replacement and leaves the original unchanged because JavaScript strings are immutable.
|
||||
|
||||
```js
|
||||
const text = "I like cats";
|
||||
|
||||
@@ -300,7 +300,7 @@ const text = "HELLO, WORLD!"
|
||||
console.log(text.toLowerCase()); // "hello, world!"
|
||||
```
|
||||
|
||||
- **The `replace()` Method**: This method is used to find a specified value (like a word or character) in a string and replace it with another value.
|
||||
- **The `replace()` Method**: This method allows you to find a specified value (like a word or character) in a string and replace it with another value. The method returns a new string with the replacement and leaves the original unchanged because JavaScript strings are immutable.
|
||||
|
||||
```js
|
||||
const text = "I like cats";
|
||||
|
||||
Reference in New Issue
Block a user