From 723dc57a606d89a481cf0d1605a1c646b2ed3b1f Mon Sep 17 00:00:00 2001 From: Jana Maire <33980489+joha1na@users.noreply.github.com> Date: Sun, 29 Jun 2025 23:38:46 +0200 Subject: [PATCH 1/4] Add documentation for the JavaScript .endsWith() method --- .../strings/terms/endsWith/endsWith.md | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 content/javascript/concepts/strings/terms/endsWith/endsWith.md diff --git a/content/javascript/concepts/strings/terms/endsWith/endsWith.md b/content/javascript/concepts/strings/terms/endsWith/endsWith.md new file mode 100644 index 00000000000..e76072458f2 --- /dev/null +++ b/content/javascript/concepts/strings/terms/endsWith/endsWith.md @@ -0,0 +1,48 @@ +--- +Title: '.endsWith()' +Description: 'Checks whether a string ends with the specified characters. It returns true if it does, otherwise false.' +Subjects: + - 'Web Development' + - 'Computer Science' +Tags: + - 'Strings' + - 'Methods' +CatalogContent: + - 'introduction-to-javascript' + - 'paths/front-end-engineer-career-path' +--- + +The **`.endsWith()`** JavaScript string method checks whether a string ends with the characters of a specified string, returning `true` if the string ends with the specified characters and `false` otherwise. An empty string (`""`) as the specified string returns `true`. The method is case-sensitive. + +## Syntax + +```pseudo +string.endsWith(searchString, endPosition); +``` + +- The `searchString` specifies the characters that will be checked for at the end of the string. It is case-sensitive. +- The `endPosition` is the position within the string to be treated as the end. It is optional and defaults to `string.length`. + +## Example + +Checking if a string ends with a string: + +```js +console.log('Hello, World! This is JavaScript.'.endsWith('JavaScript.')); +// Output: true + +console.log('Hello, World! This is JavaScript.'.endsWith('JavaScript')); +// Output: false + +console.log('Hello, World! This is JavaScript.'.endsWith('World', 12)); +// Output: true +``` + +## Codebyte Example + +The following example is runnable and checks if a string, ending at the specified position, ends with the specified searchString: + +```codebyte/javascript +console.log('Does Codecademy end with my?'.endsWith('my', 15)); +// Output: true +``` From fca4b1aa3e9310dd7124b8a86e7ffb5991b796f3 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Wed, 2 Jul 2025 18:55:48 +0530 Subject: [PATCH 2/4] Update endsWith.md --- .../strings/terms/endsWith/endsWith.md | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/content/javascript/concepts/strings/terms/endsWith/endsWith.md b/content/javascript/concepts/strings/terms/endsWith/endsWith.md index e76072458f2..e233e79cf5c 100644 --- a/content/javascript/concepts/strings/terms/endsWith/endsWith.md +++ b/content/javascript/concepts/strings/terms/endsWith/endsWith.md @@ -1,18 +1,18 @@ --- Title: '.endsWith()' -Description: 'Checks whether a string ends with the specified characters. It returns true if it does, otherwise false.' +Description: 'Checks if a string ends with a specified substring, returning true or false.' Subjects: - - 'Web Development' - 'Computer Science' + - 'Web Development' Tags: - - 'Strings' - 'Methods' + - 'Strings' CatalogContent: - 'introduction-to-javascript' - 'paths/front-end-engineer-career-path' --- -The **`.endsWith()`** JavaScript string method checks whether a string ends with the characters of a specified string, returning `true` if the string ends with the specified characters and `false` otherwise. An empty string (`""`) as the specified string returns `true`. The method is case-sensitive. +The **`.endsWith()`** JavaScript string method checks whether a string ends with the characters of a specified string, returning `true` if it does and `false` otherwise. It returns `true` when the specified string is empty (`""`). The method is case-sensitive. ## Syntax @@ -20,29 +20,35 @@ The **`.endsWith()`** JavaScript string method checks whether a string ends with string.endsWith(searchString, endPosition); ``` -- The `searchString` specifies the characters that will be checked for at the end of the string. It is case-sensitive. -- The `endPosition` is the position within the string to be treated as the end. It is optional and defaults to `string.length`. +**Parameters:** + +- `searchString`: The characters to search for at the end of `string`. +- `length` (optional): If provided, it considers only the first [`length`](https://www.codecademy.com/resources/docs/javascript/strings/length) characters of the string. ## Example -Checking if a string ends with a string: +In this example, the `.endsWith()` method checks if a string ends with a given substring, optionally considering only a portion of the string based on the provided length: ```js console.log('Hello, World! This is JavaScript.'.endsWith('JavaScript.')); -// Output: true console.log('Hello, World! This is JavaScript.'.endsWith('JavaScript')); -// Output: false console.log('Hello, World! This is JavaScript.'.endsWith('World', 12)); -// Output: true +``` + +The output of this code is: + +```shell +true +false +true ``` ## Codebyte Example -The following example is runnable and checks if a string, ending at the specified position, ends with the specified searchString: +The following example is runnable and checks whether a string, up to the specified position, ends with the given search string: ```codebyte/javascript console.log('Does Codecademy end with my?'.endsWith('my', 15)); -// Output: true ``` From a15a9817f8419a0b041f9402c78b772c9674c2ff Mon Sep 17 00:00:00 2001 From: Sriparno Roy <89148144+Sriparno08@users.noreply.github.com> Date: Thu, 10 Jul 2025 09:22:49 +0530 Subject: [PATCH 3/4] Update endsWith.md --- .../javascript/concepts/strings/terms/endsWith/endsWith.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/javascript/concepts/strings/terms/endsWith/endsWith.md b/content/javascript/concepts/strings/terms/endsWith/endsWith.md index e233e79cf5c..b7695dfef7d 100644 --- a/content/javascript/concepts/strings/terms/endsWith/endsWith.md +++ b/content/javascript/concepts/strings/terms/endsWith/endsWith.md @@ -12,7 +12,7 @@ CatalogContent: - 'paths/front-end-engineer-career-path' --- -The **`.endsWith()`** JavaScript string method checks whether a string ends with the characters of a specified string, returning `true` if it does and `false` otherwise. It returns `true` when the specified string is empty (`""`). The method is case-sensitive. +The **`.endsWith()`** JavaScript string method checks whether a string ends with a given substring, returning `true` if it does and `false` otherwise. It returns `true` when the specified string is empty (`""`). The method is case-sensitive. ## Syntax @@ -47,7 +47,7 @@ true ## Codebyte Example -The following example is runnable and checks whether a string, up to the specified position, ends with the given search string: +This codebyte example is runnable and checks whether a string, up to the specified position, ends with the given search string: ```codebyte/javascript console.log('Does Codecademy end with my?'.endsWith('my', 15)); From f491d392cebddf031e1a712ec8fa4c34d98993ab Mon Sep 17 00:00:00 2001 From: Sriparno Roy <89148144+Sriparno08@users.noreply.github.com> Date: Thu, 10 Jul 2025 09:25:27 +0530 Subject: [PATCH 4/4] Update endsWith.md --- content/javascript/concepts/strings/terms/endsWith/endsWith.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/strings/terms/endsWith/endsWith.md b/content/javascript/concepts/strings/terms/endsWith/endsWith.md index b7695dfef7d..57b5cb6f48f 100644 --- a/content/javascript/concepts/strings/terms/endsWith/endsWith.md +++ b/content/javascript/concepts/strings/terms/endsWith/endsWith.md @@ -1,6 +1,6 @@ --- Title: '.endsWith()' -Description: 'Checks if a string ends with a specified substring, returning true or false.' +Description: 'Checks if a string ends with a specified substring, returning true if it does and false otherwise.' Subjects: - 'Computer Science' - 'Web Development'