InterviewHubPRO
Section Overview
Q351

Question 351 of 521

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

67%
JavaScript Internals (521 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

How do you create specific number of copies of a string

The repeat() method is used to construct and return a new string which contains the specified number of copies of the string on which it was called, concatenated together. Remember that this method has been added to the ECMAScript 2015 specification. Let's take an example of Hello string to repeat it 4 times,

javascript
  "Hello".repeat(4); // 'HelloHelloHelloHello'