Coding Wiki
Most Common Coding Questions
Find answers to popular programming questions and level up your coding skills
Javascript loop through function twice
Learn how to reuse a JavaScript function in different ways.
Answer:
A JavaScript function can only be executed once, so it is not possible to loop through a function twice in the classical sense. However, you can achieve this effect by using the callback function of a loop or by recursively calling the function.
javascript
javascript
function loopThroughFunctionTwice(func) {
func();
func();
}
loopThroughFunctionTwice(function() {
console.log('Hello World!');
});