From c3aec1aef2c3175445bcd5e42d542b2c541b7f34 Mon Sep 17 00:00:00 2001 From: Hasan Abdullah <37593075+HasanAbdullah31@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:53:30 -0400 Subject: [PATCH] feat: add article for JavaScript String.startsWith() (#36015) --- .../string-prototype-startswith/index.md | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/guide/english/javascript/standard-objects/string/string-prototype-startswith/index.md b/guide/english/javascript/standard-objects/string/string-prototype-startswith/index.md index 5a00dd3750..0dda910af2 100644 --- a/guide/english/javascript/standard-objects/string/string-prototype-startswith/index.md +++ b/guide/english/javascript/standard-objects/string/string-prototype-startswith/index.md @@ -3,13 +3,23 @@ title: String.prototype.startsWith --- ## String.prototype.startsWith -This is a stub. Help our community expand it. +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`. -This quick style guide will help ensure your pull request gets accepted. +**Syntax** +```javascript +str.startsWith(searchStr[, pos]) // pos is the position in str at which to begin searching for searchStr +``` - +**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: - - - +- [String.prototype.startsWith() on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)