Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions 1-js/05-data-types/03-string/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ alert( "Wid*!*get*/!*".endsWith("get") ); // true, "Widget" ends with "get"

## Getting a substring

There are 3 methods in JavaScript to get a substring: `substring`, `substr` and `slice`.
There are 3 methods in JavaScript to get a substring: `slice`, `substring` and `substr`.

`str.slice(start [, end])`
: Returns the part of the string from `start` to (but not including) `end`.
Expand Down Expand Up @@ -356,9 +356,7 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
```

`str.substring(start [, end])`
: Returns the part of the string *between* `start` and `end` (not including `end`).

This is almost the same as `slice`, but it allows `start` to be greater than `end` (in this case it simply swaps `start` and `end` values).
: Like `slice`, returns the part of the string from `start` to (but not including) `end`; however, it allows `start` to be greater than `end` (in this case it simply swaps `start` and `end` values).

For instance:

Expand Down Expand Up @@ -400,8 +398,8 @@ Let's recap these methods to avoid any confusion:

| method | selects... | negatives |
|--------|-----------|-----------|
| `slice(start, end)` | from `start` to `end` (not including `end`) | allows negatives |
| `substring(start, end)` | between `start` and `end` (not including `end`)| negative values mean `0` |
| `slice(start, end)` | from `start` to (but not including) `end` | allows negatives |
| `substring(start, end)` | from `start` to (but not including) `end` | negative values mean `0` |
| `substr(start, length)` | from `start` get `length` characters | allows negative `start` |

```smart header="Which one to choose?"
Expand Down