# How to check if a string starts with another in JavaScript

> Learn how to check if a string starts with another in JavaScript using the startsWith() method, including its optional position parameter to start later.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2018-09-29 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-check-string-starts-with/

ES6, introduced in 2015, added the `startsWith()` method to the String object prototype.

This is _the_ way to perform this check in modern [JavaScript](https://flaviocopes.com/javascript/)

This means you can call `startsWith()` on any string, provide a substring, and check if the result returns `true` or `false`:

```js
'testing'.startsWith('test') //true
'going on testing'.startsWith('test') //false
```

This method accepts a second parameter, which lets you specify at which character you want to start checking:

```js
'testing'.startsWith('test', 2) //false
'going on testing'.startsWith('test', 9) //true
```
