feat: add article for JavaScript String.startsWith() (#36015)

This commit is contained in:
Hasan Abdullah
2019-06-25 16:53:30 -04:00
committed by Tom
parent e40c55b02a
commit c3aec1aef2

View File

@ -3,13 +3,23 @@ title: String.prototype.startsWith
---
## String.prototype.startsWith
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/javascript/standard-objects/string/string-prototype-startswith/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
The `startsWith()` method checks if the given string begins with the characters of a specified string; if it does, `startsWith()` returns `true`, otherwise `startsWith()` returns `false`.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
**Syntax**
```javascript
str.startsWith(searchStr[, pos]) // pos is the position in str at which to begin searching for searchStr
```
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
**Example**
```js
var x = "Hi Hilbert";
console.log(x.startsWith("Hi")); // true
console.log(x.startsWith("Hi", 0)); // true
console.log(x.startsWith("Hi", 3)); // true
console.log(x.startsWith("Hi", 4)); // false
```
*Note*: if the second argument to `startsWith()` is not provided, the start position defaults to 0 (the beginning of the string).
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
- [String.prototype.startsWith() on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)