I'm working on a code right now and in this code are some parts which I not understand. Especially the setInterval part in which are empty parentheses and comparing with the comparing operator => with the content of the curly braces. Further if the querySelector is better than defining an id and access the html elements with getElementById. Lastly I want to know if the onclick method which is not in HTML part but in the javascript part is a implemented method of javascript
const s = document.querySelector('span');
const b = document.querySelector('button');
let interval = null;
b.onclick = () => {
// Start the interval
if (!interval) {
interval = setInterval(() => {
s.innerText = parseInt(s.innerText) - 1;
}, 1000);
b.innerText = "Pause";
} else {
clearInterval(interval);
interval = null;
b.innerText = "Resume";
}
}
<span>100</span>
<button>start</button>