JavaScript String startsWith() Method

You are Here:

JavaScript String startsWith() Method

The startsWith() method returns a Boolean value indicates whether a string begins with the characters of a specified string.

Note: This method is case sensitive.

startsWith() with searchValue

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var str = "Hello there my old friend"; var result = str.startsWith("Hello"); document.write(result); </script> </body> </html>

Syntax

str.startsWith(searchValue, start)

Parameter Values

ValueTypeExplanation
searchValueRequiredSpecifies the characters to be searched for at the start of this string.
startOptionalSpecifies the position to start the search.
If omitted, the default value is '0'.

Return Value

ValueExplanation
trueIf the string starts with the value.
falseIf the string does not starts with the value.

startsWith() with searchValue and Start Index

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var str = "Hello there my old friend"; var result = str.startsWith("my", 12); document.write(result); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author