Answers for "change variable inside function javascript"

0

change a variable outside a function js

var global = "Global Variable"; //Define global variable outside of function

function setGlobal(){
       global = "Hello World!";
};
setGlobal();
console.log(global); //This will print out "Hello World"
Posted by: Guest on September-12-2020
0

change variable inside function js

var a = 10;

myFunction();

function myFunction(){
   a = 20;
}

alert("Value of 'a' outside the function " + a); //outputs 20
Posted by: Guest on May-04-2021

Code answers related to "change variable inside function javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language