Skip to content

Add Term Entry for the JavaScript .endsWith() method #7184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions content/javascript/concepts/strings/terms/endsWith/endsWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
Title: '.endsWith()'
Description: 'Checks if a string ends with a specified substring, returning true if it does and false otherwise.'
Subjects:
- 'Computer Science'
- 'Web Development'
Tags:
- 'Methods'
- 'Strings'
CatalogContent:
- 'introduction-to-javascript'
- 'paths/front-end-engineer-career-path'
---

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

```pseudo
string.endsWith(searchString, endPosition);
```

**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

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.'));

console.log('Hello, World! This is JavaScript.'.endsWith('JavaScript'));

console.log('Hello, World! This is JavaScript.'.endsWith('World', 12));
```

The output of this code is:

```shell
true
false
true
```

## Codebyte Example

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));
```