LearnFrenzy
Sign in Take a free test

String Methods · Exercise 1 of 4

String Methods String Methods MCQ

  • 15 questions
  • Page 2 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 11 Medium

What does "9876543210".replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3") return?

A "($1) $2-$3"
B "(9876543210)"
C "(987) 654-3210"
D "987 654 3210"
Question page & discussion
Question 12 Medium

What does "banana".includes("ban", 1) return?

A true
B 1
C false – the search starts at index 1, after the only "ban"
D -1
Question page & discussion
Question 13 Easy

What do the flags in /error/gi mean?

A g: greedy, i: integer
B g: group, i: insert
C g: find all matches, i: ignore case
D g: global variable, i: inline
Question page & discussion
Question 14 Hard

Why can const re = /\d/g; make re.test("a1") return true and then false on the next call with the same string?

A A global regex stores lastIndex and continues searching from there on the next call
B test() caches its result
C Strings change after testing
D Digits can only be matched once per program
Question page & discussion
Question 15 Easy

Which method returns true or false?

A indexOf
B search
C match
D startsWith
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links