Q1. What Are String Methods in JavaScript?
String methods are built-in functions used to manipulate and work with text values. These methods help perform operations like searching, replacing, converting case, and extracting text.
String methods do not modify the original string because strings are immutable. They return a new string instead.
String methods do not modify the original string because strings are immutable. They return a new string instead.
Q2. What is the length Property in Strings?
The length property returns the number of characters in a string.
Example
Output
Example
let text = "JavaScript";console.log(text.length);Output
10Q3. What is the slice() Method?
The slice() method extracts a portion of a string and returns it as a new string.
Example
Output
Example
let text = "JavaScript";console.log(text.slice(0, 4));Output
JavaQ4. What is the substring() Method?
substring() is similar to slice() and is used to extract characters between two positions.
Example
Output
Example
let text = "JavaScript";console.log(text.substring(4, 10));Output
ScriptQ5. What is the replace() Method?
The replace() method replaces part of a string with another value.
Example
Output
Example
let text = "Hello World";console.log(text.replace("World", "JavaScript"));Output
Hello JavaScript