Algorithms and Data Structures · Junior · Question 45 of 75

What is the complexity of building a string with += in a loop in modern JavaScript engines?

Explanation

Strings are immutable, but engines such as V8 use ropes, so repeated += is not copied every time and stays practical. In languages without this optimization the classic advice is to collect parts in an array and join them.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 45

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz