0

I am totally confused about object being passed by reference. In one book I read about "primitive data types are passed by value and obj are passed by ref." another one says "in ecmascript everything is passed by value" in another one it's "objects are not passed by value" Why is't there a standard thing to consider. I tried it on dev console and results are even more confusing.

Any help or reference ?

Hrishikesh
  • 335
  • 1
  • 13
  • 1
    And [Does JavaScript pass by reference?](http://stackoverflow.com/questions/13104494/does-javascript-pass-by-reference) – pishpish Apr 11 '16 at 12:54
  • 1
    Objects are passed by reference. Other types such as string, number etc are passed by value. If you have any specific code in which you have confusion, please share. – Avinash Apr 11 '16 at 12:54
  • Everything is quite "natural": strings and numbers are passed by value, objects are passed by reference... – MarcoS Apr 11 '16 at 12:56
  • 1
    @Avinash your reply is not accurate. try passing an object to a function and then replacing the object. You will be confused. Go through the above linked answers – Suman Lama Apr 11 '16 at 12:57
  • 2
    It's always pass by value, but some values are references. ;-) – RobG Apr 11 '16 at 12:59
  • @Avinash: There are references in JS (they're called objects), but there is no pass-by-reference. – Bergi Apr 11 '16 at 13:52
  • Yes. Correct. Thanks for rectifying. I had the concept correctly in my mind but couldn't convey it in correct words. – Avinash Apr 11 '16 at 13:54

0 Answers0