JavaScript Glossary - Lesson #26

JavaScript String .startsWith() Method

The startsWith method takes a string parameter and checks if the calling string starts with the value provided. It returns a Boolean value, true if the string starts with the provided value and false if not. It is case sensitive meaning the case of the search term needs to match that of the calling string.

js
""The lazy brown fox just couldn't move"".startsWith(""The"")
// true

This method:

  • Takes a string value.
  • Checks if the calling string object begins with the provided parameter.
  • Returns true or false
js
const search = string.startsWith(searchTerm, startIndex)

searchTerm The term to be searched for at the start of the string.

startIndex The start index to begin searching for the searchTerm. It defaults to 0

It returns true if the string starts with the searchTerm and false if otherwise.

Want to improve your coding and design skills?

I'm continually researching the best practices and tools for coding.
Join 50,000+ developers looking to make cool stuff.

We value your privacy. 1-click unsubscribe.

Chris Sev

Chris Sev

Chris Sev is the co-founder of Better Dev. Coding better every day. Previously he created Scotch.io which was acquired.

Comments

What did you think of the article? Let us know!
(these comments are powered by GitHub issues and use 0 trackers)