<!DOCTYPE html>
<
html
>
<
head
>
<
title
>
How to execute setInterval function without
delay for the first time in JavaScript ?
</
title
>
</
head
>
<
body
>
<
h1
style
=
"color: green"
>
GeeksforGeeks
</
h1
>
<
b
>
Execute the setInterval function
without delay the first time
</
b
>
<
p
>
Click on the button to execute the
setInterval() function without delay.
</
p
>
<
button
onclick
=
"startSetInterval()"
>
Start immediate setInterval
</
button
>
<
script
type
=
"text/javascript"
>
let count = 1;
function exampleFunction() {
console.log('Function Executed! ' + count);
count = count + 1;
}
function noDelaySetInterval(func, interval) {
func();
return setInterval(func, interval);
}
function startSetInterval() {
noDelaySetInterval(exampleFunction, 3000);
}
</
script
>
</
body
>
</
html
>