How exactly is JS triggering the button's onclick function even before its been clicked during page load?
P.S:I come from PYTHON background
var btn = document.getElementById("btn")
// this works fine (alert box appears when clicked)
btn.onclick = function(){
alert('clicked')
}
// this shows alert box when the page loads when clearly onclick is mentioned
function foo(){
alert('clickedd')
}
btn.onclick = foo()
This is for the simple HTML button inside a form table.