My HTML code is below: My question is, why does it show "before" dialog when clicking Button 1, but show "after" dialog when clicking Button 2?
<html>
<body>
<button id="b1">Button 1</button>
<button id="b2" onclick="OnClick();">Button 2</button>
<script>
var OnClick = function(){alert("before");};
document.getElementById("b1").addEventListener("click", OnClick);
var OnClick = function(){alert("after");};
</script>
</body>
</html>
JSFiddle link: https://jsfiddle.net/72chrqnf/