I have setTimeout function which need to execute greeting function after a specific milliseconds 2958219351 but it execute function directly without waiting for 2958219351 but when i specific setTimeout function with 5000 milliseconds it wait for 5 seconds then execute function.
Below is code for 2958219351 milliseconds
<!DOCTYPE html>
<html>
<body>
<h2>The setTimeout() and clearTimeout() Methods for 2958219351 milliseconds</h2>
<p>Click "Stop" to prevent myGreeting() to execute.</p>
<h2 id="demo"></h2>
<button onclick="myStopFunction()">Stop!</button>
<script>
const myTimeout = setTimeout(myGreeting, 2958219351);
function myGreeting() {
document.getElementById("demo").innerHTML = "Happy Birthday!"
}
function myStopFunction() {
clearTimeout(myTimeout);
}
</script>
</body>
</html>
Below is code for 5000 milliseconds
<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The setTimeout() and clearTimeout() Methods</h2>
<p>Click "Stop" to prevent myGreeting() to execute. (You have 5 seconds)</p>
<h2 id="demo"></h2>
<button onclick="myStopFunction()">Stop!</button>
<script>
const myTimeout = setTimeout(myGreeting, 5000);
function myGreeting() {
document.getElementById("demo").innerHTML = "Happy Birthday!"
}
function myStopFunction() {
clearTimeout(myTimeout);
}
</script>
</body>
</html>
I don't know why it execute directly setTimeout
function without waiting for 2958219351 milliseconds