![](/img/trans.png)
[英]Why does assigning to part of a string (using array syntax) not throw an error in javascript?
[英]Why does assigning Infinity in JavaScript not throw an error, but not work?
为什么无穷大在尝试重新分配但不可分配时不给出错误?
var x = 3;
x = 1; // good, normal
true = 3; // error, normal
Infinity = 4; // no error
console.log(Infinity); // Infinity
你可以在这里阅读:
Infinity 是全局 object 的属性,换句话说,是全局 scope 中的变量。
由于它是一个全局属性,您可以访问它并分配任何值。 但是,当您处于非严格模式时,将值分配给非Writable 属性不会引发任何异常,并且不会更改属性的值。
如果您使用“严格模式”,则会引发异常。
"use strict" Infinity = 4;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.