Answers for "use a js variable outside function"

4

how to get variable value outside function in javascript

/* Not putting "var", "let" or "const" will make the variable Public
And usable outside a functin */

function Play(){
  	Video = 12 // Seconds
	var Length = 15
}
console.log(Video) // Prints 12
console.log(Length) // "Lenght" is undefined
Posted by: Guest on July-18-2021
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

Code answers related to "use a js variable outside function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language