Does the addeventlistner create a new scope?

Does the addeventlistner create a new scope?
0

#1

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


#2

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.


#3

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


#4

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.


#5

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


#6

thank you so much now i got it