LearnFrenzy
Sign in Take a free test

String Methods · Exercise 1 of 4

String Methods String Methods MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript string methods: replace and replaceAll, padStart, trim, split with limits, match and matchAll, search, includes positions, localeCompare, normalize, regex flags and lastIndex. Pick an option to check your answer instantly.

Question 1 Easy

What is "1,000,000".replace(",", "")?

A "1000000"
B "1,000,000"
C "1000 000"
D "1000,000"
Question page & discussion
Question 2 Hard

What happens with "a.b.c".replaceAll(/\./, "-")?

A It returns "a-b-c"
B It returns "a-b.c"
C A TypeError: replaceAll requires a global (g) regex
D It returns "a.b.c"
Question page & discussion
Question 3 Easy

Which expression turns the day number 5 into "05"?

A (5).padStart(2, "0")
B "5".padEnd(2, "0")
C "5".repeat(2)
D String(5).padStart(2, "0")
Question page & discussion
Question 4 Easy

What is "\t Asha Rao \n".trim()?

A "AshaRao"
B "\tAsha Rao"
C "Asha Rao"
D "Asha Rao \n"
Question page & discussion
Question 5 Medium

What does "a:b:c:d".split(":", 2) return?

A ["a", "b:c:d"]
B ["a:b", "c:d"]
C ["a", "b", "c", "d"]
D ["a", "b"]
Question page & discussion
Question 6 Medium

What does "x1y22".match(/(\d)+/g) return?

A ["1", "22"] – with g, only the matched strings, no group details
B ["1", "1"]
C A match object with groups
D [1, 22] as numbers
Question page & discussion
Question 7 Hard

Which statement about str.matchAll(regex) is correct?

A The regex must have the g flag, and the result is an iterator of match objects (with groups and index)
B It returns an array of strings like match with g
C It works without g and returns only the first match
D It returns null when nothing matches
Question page & discussion
Question 8 Medium

What is the main difference between search and indexOf?

A search returns a boolean
B indexOf is case-insensitive
C search returns all positions
D search takes a regular expression; indexOf looks for exact text and accepts a start position
Question page & discussion
Question 9 Medium

Which comparator sorts ["img12", "img2", "img1"] as img1, img2, img12?

A (a, b) => a.localeCompare(b, undefined, { numeric: true })
B (a, b) => a - b
C (a, b) => a > b
D The default sort()
Question page & discussion
Question 10 Hard

Two strings both display as "José" but a === b is false. What is the likely cause and fix?

A One string has a hidden space – use trim()
B é is stored as one character in one string and as e + combining accent in the other – compare a.normalize() === b.normalize()
C They have different case – use toLowerCase()
D Strings with accents cannot be compared
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links