trying to understand the concept of being unable to mutate strings/numbers in javascript -


in javascript, can reassign variable like:

var x = 10; x+=10; console.log(x); //prints 20 console 

but if take example of seemingly similar activity unexpected result:

var originalvar = 1;  changemyvar(originalvar);  function changemyvar(myvar) {   myvar += 1000;   return myvar; }  console.log(originalvar); //prints 1 console 

i see 1 in same. passing variable argument function. i'm reassigning value within function. , i'm returning , printing variable. mutation?

primitives function parameters passed value in javascript. therefore myvar in changemyvar function not reference originalvar new variable value of originalvar.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -