原始值与参考值 [英] Primitive value vs Reference value

查看:140
本文介绍了原始值与参考值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一本名为面向Web开发人员的专业Javascript的书,它说:变量由参考值或原始值指定。参考值是存储在内存中的对象。然后它没有说明如何存储原始值。所以我猜它没有存储在内存中。基于此,当我有这样的脚本时:

I read a book called "Professional Javascript for web developer" and it says: "Variable is assigned by Reference value or Primitive Value. Reference values are objects stored in memory". And then it says nothing about how Primitive value is stored. So I guess it isn't stored in memory. Based on that, when I have a script like this:

var foo = 123;

Javascript如何记住 foo 变量以后使用?

How does Javascript remember the foo variable for later use?

推荐答案

变量可以保存两种值类型中的一种:原始值参考值

A variable can hold one of two value types: primitive values or reference values.


  • 原始值是存储在堆栈上的数据。

  • 原始值直接存储在变量访问的位置。

  • 参考值对象存储在

  • 参考值存储在变量location是指向存储对象的内存中的位置的指针。

  • 原始类型包括未定义 Null Boolean Number String

  • Primitive values are data that are stored on the stack.
  • Primitive value is stored directly in the location that the variable accesses.
  • Reference values are objects that are stored in the heap.
  • Reference value stored in the variable location is a pointer to a location in memory where the object is stored.
  • Primitive types include Undefined, Null, Boolean, Number, or String.

基础:

对象是ag财产的格言。属性可以引用对象原语基元是值,它们没有属性。

Objects are aggregations of properties. A property can reference an object or a primitive. Primitives are values, they have no properties.

已更新:

Updated:

JavaScript有6种原始数据类型:字符串数字布尔未定义符号(ES6中的新功能)。除了null和undefined之外,所有基元值都具有包围原始值的对象等价物,例如, String 对象包装字符串基元。所有原语都是不可变的。

JavaScript has 6 primitive data types: String, Number, Boolean, Null, Undefined, Symbol (new in ES6). With the exception of null and undefined, all primitives values have object equivalents which wrap around the primitive values, e.g. a String object wraps around a string primitive. All primitives are immutable.

这篇关于原始值与参考值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆