Cant figure this out


#1

If I redefine a global variable inside a function, is there a way to make that effect the global value as well?


#2

yep, pretty easy:

var variable = 5;
var example = function(){
  variable += 5;
  
}
example()
console.log(variable)

don't use a var keyword in the function, this will make the variable local (only exist inside the function), without the var keyword the global variable will be updated


#3

Thanks! That makes sense.


#4