I'm relatively new to JavaScript and can't understand the code from the book Eloquent Javascript
. It is used to fire mousemove not frequenter than 500ms, but I can't understand what is null here for.
let scheduled = null;
window.addEventListener("mousemove", event => {
if (!scheduled) {//*if scheduled ==null
setTimeout(() => {
document.body.textContent =
`Mouse at ${scheduled.pageX}, ${scheduled.pageY}`;
scheduled = null;
}, 500);
}
scheduled = event;
});