So I coded this function expecting to create a variable, but it throw me an error
function createMyName(){
var Myname = 'something';
console.log(Myname); //something
}
console.log(Myname) //⚠ Myname is not defined
So I coded this function expecting to create a variable, but it throw me an error
function createMyName(){
var Myname = 'something';
console.log(Myname); //something
}
console.log(Myname) //⚠ Myname is not defined
You need to define the variable outside the function than change it inside the function when defining the function use global like the following
global.myGlobalVariable = "Value 1";
function myFunction(){
myGlobalVariable = "Value 2";
}
it would be changed as a global variable