4.1 primitive and reference values

  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.

时间: 2024-08-02 03:12:17

4.1 primitive and reference values的相关文章

Java中的原始类型(Primitive Types)与引用类型(Reference Values)

Java虚拟机可以处理的类型有两种,一种是原始类型(Primitive Types),一种是引用类型(Reference Types). 与之对应,也存在有原始值(Primitive Values)和引用值(Reference Values)两种类型的数值可用于变量赋值.参数传递.方法返回和运算操作. 原始类型与值 Java虚拟机支持的原始数据类型包括数值类型.布尔类型和returnAddress类型. 数值类型包括:整数类型和浮点类型. 整数类型包括: 1.byte 2.short 3.int

javascript fundamental concept

function: function本身是一个object,它可以被赋值给任何变量 immediate invoked function expression(IIFE):  function(){}() method vs function: 一个method是一个对象的一个函数属性(a method is a function that is a property of an object)例如: var console={ log:function(){} } console.log(“l

= splice

1 <script> 2 function wf(w){ 3 console.log(w); 4 } 5 6 var wa = [3,66,7]; 7 var wb = wa; 8 wa.splice(1,1); 9 wf(wa); 10 wf(wb); 11 12 var waa = [3,66,7]; 13 var wbb = waa; 14 waa = [123,4]; 15 wf(waa); 16 wf(wbb); 17 18 var wae = [3,66,7]; 19 var wb

spring源码分析(一)IoC、DI

创建日期:2016.08.06 修改日期:2016.08.07 - 2016.08.12 交流QQ:992591601 参考书籍:<spring源码深度解析>.<spring技术内幕> 参考文章:http://www.cnblogs.com/xing901022/p/4178963.html http://www.myexception.cn/program/1031276.html http://blog.csdn.net/qian_348840260/article/detai

Objective-C Programming The Big Nerd Ranch Guide 笔记 19-37

Properties are either atomic or nonatomic, The difference has to do with multithreading. atomic is the default value. Properties are either readonly or readwrite. readwrite is the default value. Whenever you declare a property that points to an NSStr

【Java虚拟机结构(第1部分)数据类型】摘要

<Java虚拟机规范(Java SE 7版)>作者:Tim Lindholm.Frank Yellin.Gilad Bracha.Alex Buckley 摘要:第二章 Java虚拟机结构(第1部分) 本规范描述的是一种抽象化的虚拟机的行为,而不是任何一种被广泛使用的虚拟机实现. 2.1 Class 文件格式 编译后被Java虚拟机所执行的代码使用了一种平台中立(不依赖于特定硬件及操作系统的)的二进制格式来表示,并且经常(但并非绝对)以文件的形式存储,因此这种格式被称为Class文件格式. 2

转载 Java基本数据类型

Java语言是静态类型的(statical typed),也就是说所有变量和表达式的类型再编译时就已经完全确定.由于是statical typed,导致Java语言也是强类型(Strong typed)的.强类型意味着每个变量都具有一种类型,每个表达式具有一种类型,并且每种类型都是严格定义的,类型限制了变量可以hold哪些值,表达式最终产生什么值.同时限制了这些值可以进行的操作类型以及操作的具体方式.所有的赋值操作,无论是显式的还是在方法调用中通过参数传递,都要进行类型兼容性检查. 1. 数据类

Object类的源码分析

JDK 1.8中Object 的源码如下: 1 public class Object { 2 3 private static native void registerNatives(); 4 static { 5 registerNatives(); 6 } 7 8 /** 9 * Returns the runtime class of this {@code Object}. The returned 10 * {@code Class} object is the object tha

(java) 第二周学习总结

在java源代码中,每个变量都必须声明一种类型(type).有两种类型:primitive type和reference type.引用类型引用对象(reference to object),而基本类型直接包含值(directly contain value).因此,Java数据类型(type)可以分为两大类:基本类型(primitive types)和引用类型(reference types).primitive types 包括boolean类型以及数值类型(numeric types).n