alert('Hi')
Here alert is an inbuilt function called by browser which opens a alert box.
function callAlert(){
alert('Hi');
}
Here callAlert is a custom function which calls the inbuilt function alert
In your example, when appending a click event, you have to define the function
document.getElementById("myButton").onclick = alert('Hi!') //alert is
already executed
document.getElementById("myButton").onclick = function (){ alert('Hi!') };
//a function is defined/declared which will be executed when the onclick action is performed