Context: I'm trying to learn some JavaScript and HTML. I've got some arrays and wanted to normalize them so that their entries sum to 1. To do this, I defined a function called normalize (that took an array as its argument). Things were working fine until I tried to incorporate a call to my normalize function as part of a button click in my main .html file. Below is a working dummy example with the array stuff omitted.
<script>
function normalize () {return 1;};
</script>
<input type="button" onclick="console.log(normalize()); //prints undefined when clicked">
<script>
console.log(normalize()); // prints 1 as intended
</script>
But if I change the name of the function to something other than normalize, then both calls work just fine:
<script>
function foo () {return 1;};
</script>
<input type="button" onclick="console.log(foo()); //prints 1 when clicked">
<script>
console.log(foo()); // prints 1
</script>
My question is: why is the onclick call behaving differently when the function is named normalize? I would've expected it to throw an error or something, given that onclick seems to be calling some external normalize function on one of my arrays. I did a quick search for other normalize functions, and I did see that there's an HTML DOM normalize method, but I don't see why it's being called (if it is being called!) instead of my intended function. What's going on with the onclick normalize call?
Thanks in advance for any help you can give!