码迷,mamicode.com
首页 > 其他好文 > 详细

4.1 primitive and reference values

时间:2015-05-08 14:50:03      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

  ECMAScript variables may contains two different types of data: primitive values and reference values. Primitive values are simple atomic pieces of data, while reference values are objects that may be made up of multiple values.

  The five primitive types are: Undefined, Null, Boolean, Number and String.

  primitive values are accessed by value, while reference values are accessed by reference.

 

Copying Values

  Primitive and reference values act differently when copied from one variable to another.

  When a primitive value is assigned from one variable to another, the value stored on the variable object is created and copied into the location for the new variable.

  When a reference value is assigned from one variable to another, the value stored on the variable object is also copied into the location for the new variable. The different is that this value is actually a pointer to an object stored on the heap. Once the operation is complete, two variables point to exactly the same object, so changes to one are reflected on the other.

4.1 primitive and reference values

标签:

原文地址:http://www.cnblogs.com/linxd/p/4487533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!