Example 1 — Basic repeat()
Concatenate a phrase several times inside a sentence.
const mood = "Happy! ";
console.log(`I feel ${mood.repeat(3)}`);
// I feel Happy! Happy! Happy! How It Works
- Start with a unit.
moodis"Happy! "(note the trailing space). - Repeat three times.
mood.repeat(3)concatenates that unit back-to-back. - Embed in a template. The result lands after
"I feel ". - Original unchanged.
moodis still a single"Happy! ".

