changing local variable inside a function

Hey guys,

Id basically like to know if it is possible, and how to pull off to use a function to change the content of a variable that was made in the function that runs the function that changes said variable. This is an example I made for my problem:

Code:
function functiondad() {
    var turbotest = 2;
    functionson(turbotest)
    console.log(turbotest)
}

function functionson(A) {
    A = 4;
}

Thanks in advance!
Short answer: No
Long answer: It's all about variable scoping, this is one of the most important concepts in Javascript.

Your variable "turbotest" is local to the function "functiondad", nothing can access it outside of that function. Any changes you want to do have to be in the context of "functiondad".

The way that you would do what you want is to return the value from the inner function to the outer function and assign the value to the variable.

In the spirit of your example:

Code:
function functiondad() {
   var turbotest = 2;
   turbotest = functionson(turbotest);
   console.log(turbotest);
}

function functionson(A) {
   return A * 2;
}
@Aloe Guvner ahhh right... I forgot it would work like that too, thanks!

Original thread: https://forums.rpgmakerweb.com/threads/changing-local-variable-inside-a-function.96725/