I’m using jQuery. Can someone please explain why I cannot modify the global variable x within the ,click function below? After clicking on a link, the value of x is still an empty string, not “test”. I’ve noticed that this occurs with .click functions. I’m trying to understand why and how I can fix it without just putting the console.log(x) inside my click function. I specifically want to know how a global variable can be modified within the click function. I tried to make the example easy to understand and it’s just a generic example to communicate my issue.
var x = " ";
$('a').click(function() {
x = "test";
});
console.log(x);
Thanks guys!