Monday, 6 June 2016

jquery - How to change the value of variable in a function in javascript?



var e = 15;


function change_value(e){

e = 10;
}

change_value(e);

console.log(e);



The Value of e is still 15.


Answer



The e inside the function scope is different from the e inside the global scope.



Just remove the function parameter:



var e = 15;

function change_value(){

e = 10;
}

change_value();
console.log(e);

No comments:

Post a Comment