2

Here, i have some doubts with this piece of code i found in a job application test i made a few hours ago.

function foo(x){
    x['key'] = "new value"
}

var a = {'key': "old value"}

foo(a)

console.log (a)

Why is the a.key being updated when im just asigning a new value to the function parameter not to the global var?

Fiddle JS: https://jsfiddle.net/SoujiCode/gu2xcwe6

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Souji
  • 21
  • 2

0 Answers0