# The String substring() method

> Learn how the JavaScript substring() method returns part of a string and how it differs from slice() by turning any negative argument into 0.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-03-03 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-string-substring/

`substring()` returns a portion of a string and it's similar to [`slice()`](https://flaviocopes.com/javascript-string-slice/), with some key differences.

If any parameter is negative, it is converted to `0`.
If any parameter is higher than the string length, it is converted to the length of the string.

So:

```js
'This is my car'.substring(5) //'is my car'
'This is my car'.substring(5, 10) //'is my'
'This is my car'.substring(5, 200) //'is my car'
'This is my car'.substring(-6) //'This is my car'
'This is my car'.substring(-6, 2) //'Th'
'This is my car'.substring(-6, 200) //'This is my car'
```
