Three ways to repeat a string in JavaScript
Sonya Moisset

I actually got a question like this in an interview for a company, to which I gave a solution like the first one you detailed here. I thought it was too simple to be true but it turns out that the interviewer was looking for something else.

Since strings in JavaScript are immutable, concatenation for strings with “+” actually create n copies of said string, one for each iteration. Because of this I think the solution was to first create an n item array and then join it, but I can’t recall since I failed the interview 😭