DEV Community

Laxman Nemane
Laxman Nemane

Posted on

πŸš€ Day of Strengthening My DSA Fundamentals – JavaScript String Methods

Today I learned the remaining string methods in JavaScript.

Yesterday, I posted on Dev Community about the string methods I had already learned.
Here is the URL of that post:
https://dev.to/laxmann/day-of-strengthening-my-dsa-fundamentals-javascript-string-methods-44b9

In that post, I covered the earlier methods.
Now I’m sharing the methods I learned today.

Let’s start by revising the string methods:

πŸ”Ή slice()
Extracts a section of a string and returns a new string without modifying the original one.

It takes two parameters:
startIndex
endIndex

The string between these two indexes is returned.

  • The startIndex is included.
  • The endIndex is excluded.

πŸ”Ή split()
Converts a string into an array.
It takes two parameters:
separator
limit

The separator defines where to split the string.
The limit defines how many items you want in the resulting array.

πŸ”Ή substring()
Works similarly to slice().

It takes:
startIndex
endIndex

And returns the part of the string between those indexes.

πŸ”Ή trim()
Removes whitespace from both ends of the string.

πŸ”Ή trimEnd()
Removes whitespace from the end of the string.

πŸ”Ή trimStart()
Removes whitespace from the beginning of the string.

πŸ”Ή startsWith()
Checks whether a string starts with a given character or substring.

Returns:
true
false

πŸ”Ή toLocaleUpperCase()
Converts a string to uppercase using locale-specific case mapping.

It can take a locale as a parameter.

πŸ”Ή toUpperCase()
Converts a string to uppercase using default Unicode rules (not locale-specific).

πŸ”Ή toLowerCase() / toLocaleLowerCase()
Same concept as uppercase methods, but converts the string to lowercase.

βœ… What I Learned Today
Today I strengthened my understanding of:

  • How string methods return new values
  • The difference between slice() and substring()
  • How split() works internally

The difference between locale-based and default Unicode case conversion

If you see any mistakes or have suggestions, please let me know.
I continually improve my DSA fundamentals.

Top comments (0)