[Solved] Trouble with scopes in Javascript [closed]


First of all your code contains some syntax errors.
You can change the value of myVariable inside function because here it is a global variable and accessible to the function.

The problem you are facing may be with the place where you are calling the function.

var myVariable = {};

function changeMyVariable() {
  myVariable.mykey = 'xyz';
}

console.log(myVariable);//before calling function
changeMyVariable();
console.log(myVariable);//after calling function

1

solved Trouble with scopes in Javascript [closed]