LearnFrenzy
Sign in Take a free test

Strings · JavaScript Strings MCQ · Question 13

Building a long string Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

A loop produces 10,000 lines of CSV. Which approach is clear and predictable?

  • A Push each line into an array and call join("\n") once at the end Correct
  • B Modify one character of the string at a time with str[i] = …
  • C Create a new String object for each line
  • D Use str.reverse() at the end
Correct Answer: Option A

Strings cannot be modified in place. Collecting parts and joining once is idiomatic (engines also optimise +=, but join keeps intent clear).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links