Skip to main content
InterviewHubPRO
Section Overview
Q351

Question 351 of 536

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

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

How do you create specific number of copies of a string

senior LevelCode ExampleAsync & PromisesEvent LoopHTTP & REST APIs

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'