0% found this document useful (0 votes)
6 views6 pages

JavaScript String Methods Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

JavaScript String Methods Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q1.

What will be output the following print statement in js


[Link]("hari\"".length)

Ans:
The output prints the length of the string (ie;5) including the double quotes, the backslash within the
string is treated as an escape sequence.

Q2. Explore the includes, startswith and endswith function of a string

In JavaScript, the includes, startsWith, and endsWith functions are used with strings to check for
specific patterns.

. `includes`: Determines if a string contains another string. Example:

let str = "Hello, world!";


let containsHello = [Link]("Hello");
[Link](containsHello); // true
3
. `startsWith`: Checks if a string starts with a specified prefix. Example:

let str = "Hello, world!";


let startsWithHello = [Link]("Hello");
[Link](startsWithHello); // true
2
. `endsWith`: Checks if a string ends with a specified suffix. Example:

let str = "Hello, world!";


let endsWithWorld = [Link]("world!");
[Link](endsWithWorld); // true
1
Q3. Extract the amount out of the string
"Please give Rs 10000"
Q4. Try to Change 4th character of a given string
"Where you able to do it?"

Q5. Note on All string methods with programs


Q6. Write a function to check if two strings are anagrams of each other. Anagrams have the same
characters but in a different order. For example, "listen" and "silent" are anagrams.
Q7. Write a function to count the number of vowels and consonants in a given string.

Q8. Write a function that capitalizes the first letter of each word in a sentence. For example,
"hello world" should become "Hello World.“
Q9. Implement a function to perform basic string compression using the counts of repeated
characters. For example, the string "aabcccccaaa" would become "a2b1c5a3.“
Q10. Implement a basic string compression without creating a separate function. Use loops and
conditional statements to create the compressed string.

You might also like