Hey there! I'm diving into the world of Javascript and I've come across this interesting code that changes an image every four seconds. Surprisingly, it's working perfectly fine even though I didn't include an onload event to execute the setInterval() method. How is it possible that setInterval() still got called without me explicitly calling it? Who could have triggered the setInterval() method?
<html lang="en">
<head>
<title>sliding image</title>
</head>
<body>
<img id="img1" src="" alt="" width="1200px">
<script>
let images = [
"C:\\Users\\SUDARSHAN\\Desktop\\html_UI\\images\\1200px-Heart_corazon.svg.png",
"C:\\Users\\SUDARSHAN\\Desktop\\html_UI\\images\\alex-haney-AGqzy-Uj3s4-unsplash.jpg",
"C:\\Users\\SUDARSHAN\\Desktop\\html_UI\\images\\mitchell-luo-jz4ca36oJ_M-unsplash.jpg"
];
let i = 0;
function image()
{
let img2=document.getElementById("img1");
i = (i + 1) % images.length;
img2.src = images[i];
}
window.setInterval(image,4000);
</script>
</body>
</html>