为什么说js中Number是不可变量这是《Javascript - The Definite Guide 6th》正文30页的原文.“ They can also be categorized as mutable and immutable types.A value of a mutable type can change.Objects and arrays are mutable:a JavaScript

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 13:48:01
为什么说js中Number是不可变量这是《Javascript-TheDefiniteGuide6th》正文30页的原文.“Theycanalsobecategorizedasmutableandim

为什么说js中Number是不可变量这是《Javascript - The Definite Guide 6th》正文30页的原文.“ They can also be categorized as mutable and immutable types.A value of a mutable type can change.Objects and arrays are mutable:a JavaScript
为什么说js中Number是不可变量
这是《Javascript - The Definite Guide 6th》正文30页的原文.“ They can also be categorized as mutable and immutable types.A value of a mutable type can change.Objects and arrays are mutable:a JavaScript program can change the values of object properties and array elements.Numbers,booleans,null,and undefined are immutable—it doesn’t even make sense to talk about changing the value of a number,for example.”为什么说Number,boolean是不可变量?这里的可变与不可变是什么意思?

为什么说js中Number是不可变量这是《Javascript - The Definite Guide 6th》正文30页的原文.“ They can also be categorized as mutable and immutable types.A value of a mutable type can change.Objects and arrays are mutable:a JavaScript
这里的“不可变”指的是变量本身是不会发生变化的.数字、布尔值都属于“原子”数据类型.你只能改变它的值,而不能改变它本身.而对象则不同.对象是复杂的数据类型,一个对象会包含很多原子类型或者其他的对象.你可以改版对象的属性方法,但对象还是它本身.