Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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"
Source by www.codecademy.com #
 
PREVIOUS NEXT
Tagged: #change #variable #function #js
ADD COMMENT
Topic
Name
7+9 =