I recently started going deeper about behind the scenes of JS and I got this confusion. Let's say I have a button with an onclick event attached to it. Let's say in the call stack a loop is running that takes few seconds to complete. During this period if I click on the button according to what I have understood till now, the function associated with the click event should not get executed. The callback function for the button click is stored in the callback queue through web API. The callback function won't go in the call stack until the call stack is empty. so when the loop is running the onclick function should not get executed but it is being executed Anyone who could explain to me how it is happening and clear my misconceptions.