Modify variables inside a function with javascript -


i'd know if posible, having 1 or more variables pass them function , variables modified. think posible objects, behave references, don't know.

with 1 var do:

var = increase(something); 

but if have, example, 2 variables recipies, , exchange them?

exchange_recipies(book1, book2); 

you variables parameters inside function... there way i'm missing?

edit: know can done in many ways i'll state here don't due obvious limitations:

-use global variables.

-use objects

-return array , reasign.

edit2: is possible change value of function parameter? helped me, think answer uncomplet , there ways of doing this.

if variables declared globally wouldn't need pass them function since can addressed inside function.

var = 1 function bar(){     = increase(something); } 

for example.

this means avoid changing variables parameters , can address them function (dependant on nesting, ergo, if variable declared inside function can't addressed outside of function can function inside)

function foo(){     var = 1     function bar(){         //works because exists in parent function         = increase(something)     } }  function foobar()     //something doesn't exist here return = undefined     = increase(something) } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -