Is JavaScript pass

This question already has an answer here:

  • Javascript by reference vs. by value [duplicate] 4 answers

  • Objects are passed by reference while primitives are passed by value.

    Note, that primitive values include the following:

  • number
  • String
  • boolean
  • undefined
  • null
  • You can find some more details at MDN on Functions.


    It uses an evaluation strategy named call by sharing actually.

    All types are passed by value. There's no pass-by-reference, otherwise you'd be able to modify contents of variables declared at the call site of a function. Usually people say that objects are passed by reference in JS. They're actually passed by sharing, which means you can modify an object's properties, and these changes will be visible to those that hold a reference to that object, but the reference in itself is not modifiable.


    Everything but primitives are passed by reference.
    Just about everything in JavaScript is an object. As Sirko said, Objects are passed by reference.

    So functions/arrays/objects are all passed by reference, whether you're talking about the root object attached to a var, or you're talking about an object's property/method, chained 3 dots deep, or you're talking about an object in an array, as a property of an object, in an array of objects...

    链接地址: http://www.djcxy.com/p/20976.html

    上一篇: JavaScript函数参数通过引用存储

    下一篇: JavaScript通过了吗?