function - Scope in javascript acting weird -


object passed reference in javascript. meaning change in object should reflected. in case, expected output {} console.log(a)

function change(a,b) {     a.x = 'added';     = b;//assigning {} b } a={} b={} change(a,b); console.log(a); //expected {} output {x:'added'} console.log(b) 

what happening here? should not because of functional scope far know. thank you

if added line can clearer picture of happening:

function change(a,b) {     a.x = 'added';     = b;     a.x = 'added well'; }; a={}; b={}; change(a,b); console.log(a);  //{x:'added'} console.log(b);  //{x:'added well'} 

when you're doing a = b you're assigning local variable a reference b holding.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -