Here we will cover the Quiz related to JavaScript String to clear all your concept.
Question 1
Which of the following is a valid way to declare a string variable in JavaScript?
b. string name = 'John';
a. var name = 'John';
b. const name = 'John';
c. let name = 'John';
d. All of the above
Question 2
Which method is used to concatenate two or more strings in JavaScript?
a. append()
b. join()
c. concat()
d. add()
Question 3
Which method is used to find the index of the first occurrence of a specific character or substring in a string?
a. indexOf()
b. findIndex()
c. search()
d. locate()
Question 4
Which method is used to convert a string to uppercase letters in JavaScript?
a. toLowerCase()
b. upperCase()
c. toUpperCase()
d. upper()
Question 5
Which method is used to remove whitespace from both ends of a string in JavaScript?
a. trim()
b. strip()
c. clean()
d. remove()
Question 6
Which method is used to replace a specified substring with a new substring in a string?
a. replace()
b. swap()
c. substitute()
d. switch()
Question 7
Which method is used to split a string into an array of substrings based on a specified separator?
a. slice()
b. split()
c. divide()
d. break()
Question 8
Which method is used to return the length of a string in JavaScript?
a. length()
b. size()
c. count()
d. getSize()
Question 9
Which method is used to convert a string to a number in JavaScript?
a. toInt()
b. parseInt()
c. convertToNumber()
d. castToNumber()
Question 10
Which method is used to repeat a string a specified number of times in JavaScript?
a. repeat()
b. replicate()
c. duplicate()
d. copy()
There are 14 questions to complete.