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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -