Does the addeventlistner create a new scope?

does the the addeventListener create a local scope ?,??, coz this way work for me but i don’t understand the scope rules here , coz the roundscore is in the callback function so why the roundscore is changing is the global scope

Look at the very first line of the code you posted. You declared roundscore as a global variable, so unless you declare another roundscore inside the addEventListener callback function, you change the global roundscore variable’s value.

1 Like

yes i hear you , but the roundscore is inside the callback function , ??? as far as iknow any function create her own scope

But not where you originally declared it. Any variable declared in the global scope can be referenced and changed inside functions contained in the global scope.

1 Like

They do, but they have access to anything in the global scope or any scope they are contained in (i.e. another function).

1 Like

thank you so much now i got it