String in DSA Using JavaScript (original) (raw)
Last Updated : 23 Jul, 2025
A string in JavaScript is a sequence of characters enclosed in single ('), double ("), or backticks (`). Strings in JavaScript are immutable, meaning their contents cannot be changed after creation. Any operation that modifies a string actually creates a new string.
**Example:
JavaScript `
let s = "GfG"; console.log(s[0]); console.log(s.length);
`
Common String Methods in JavaScript:
- length – Returns the number of characters in a string.
- charAt(index) – Returns the character at the specified index.
- slice(start, end) – Extracts a section of a string and returns it as a new string.
- substring(start, end) – Similar to slice(), but does not accept negative indices.
- toUpperCase() / toLowerCase() – Converts the string to uppercase or lowercase.
- trim() – Removes whitespace from both ends of a string.
- replace(searchValue, newValue) – Replaces a specified value with another value in a string.
- split(separator) – Splits a string into an array based on a specified separator.
- includes(substring) – Checks if a string contains a given substring, returning true or false.
- concat(str1, str2, ...) – Joins two or more strings together.
- Please refer JavaScript String Methods for more methods.
Easy Problems Problem On String using JavaScript
- Reverse a String
- Palindrome Check
- Check for Subsequence
- Check Anagram
- Reverse Words
- Isomorphic Strings
- Check Pangram or not
Medium Problems On String in JavaScript
- Implement Atoi
- Validate an IP address
- Find the largest word in dictionary
- Equal 0, 1, and 2
- Longest Palindromic Subsequence
- Longest substring without Repeating