I have a javascript function that calls a callback function on an event, where values from the DOM are read out.
I'm using a variable that appears nowhere else in the script, but it has values directly after being created - I already tried changing the name of the variable, but to no avail.
document.getElementById("myButton").onmouseenter = function() {
var myVariable = new Array()
console.log(myVariable)
what happens, is that the console.log directly after initializing the function already shows values:
[]
333: NaN
427: 0.1
length: 428
__proto__: Array(0
this only happens inside the callback function. I'm aware that callbacks can not always run sequentially, but how do i work around that in this example? I run into the same problem if i declare the variable outside of the callback function.