Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  74] [ 3]  / answers: 1 / hits: 25302  / 10 Years ago, thu, december 25, 2014, 12:00:00
var variable = before;

change();

alert(variable);

function change(){

variable = after;

}


Does in possible to change global variable inside function without return ? I need after call function change have output after


More From » jquery

 Answers
11

Yes, it is possible, but remember to NOT put the var keyword in front of it inside the function.



ERORR - DOES NOT WORK:





var variable = before;

change();

alert(variable);

function change() {

var variable = after;

}





WORKS:





var variable = before;

change();

alert(variable);

function change() {

variable = after;

}




[#68381] Tuesday, December 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
dominickmackenziet questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Fri, Feb 12, 21, 00:00, 3 Years ago
;