feat: add article for JavaScript String.startsWith() (#36015)
This commit is contained in:
@ -3,13 +3,23 @@ title: String.prototype.startsWith
|
|||||||
---
|
---
|
||||||
## 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:
|
#### 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)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user