when i run the following code (by clicking the button):
const div = document.querySelector( "div" )
const button = document.querySelector( "button" )
button.addEventListener( "click", () => {
console.log( 'clicked' );
div.textContent = 'printing....';
var delay = 3000 + new Date().getTime();
while ( new Date().getTime() < delay ) { }
console.log( 'after delay' );
} );
<button>Run</button>
<div></div>
div's content appears after the callback has finished, so i got upon clicking the first log ( 'clicked') and then after the 3s delay loop the second log ( 'after delay' ) and the text inside the div. Why div.textContent = 'printing....'; isn't executed after the first console.log() ? Thanks a lot (i'm new in coding and in stackoverflow , so please forgive me if i'm unclear or silly)