Variables 如何更改变量

Variables 如何更改变量,variables,Variables,设置变量后如何更改变量,如下所示: constmyvar='test' 我尝试了以下方法: myVar='test2' constmyvar='test3'您不能。这就是将变量声明为const的目的。这意味着它是一个常数-它不会改变。常数是常数。一旦将其设置为初始值,则不会对其进行更改。 只需使用标准变量类型,无需指定const var myVar = 'test'; myVar = 'another'; const site = 'Stackoverflow'; site = 'Google

设置变量后如何更改变量,如下所示:

constmyvar='test'

我尝试了以下方法:

myVar='test2'


constmyvar='test3'

您不能。这就是将变量声明为
const
的目的。这意味着它是一个常数-它不会改变。

常数是常数。一旦将其设置为初始值,则不会对其进行更改。 只需使用标准变量类型,无需指定
const

var myVar = 'test';
myVar = 'another';

const site = 'Stackoverflow';
site = 'Google'; // this will throw an error in Firefox and Chrome (but does not fail in Safari)

const site = 'fb';// trying to redeclare a constant throws an error

console.log(myVar); //outputs another
console.log(site); //Stackoverflow

也许告诉我们语言可能有帮助,它不是C或C++,因为“test”不是一个有效的字符。奇怪的是,一个750 +RP的家伙问这样的问题是什么原因?这就像试图在一种随机的人类语言中找到“出租车”这个词——它可能是“出租车”或其他听起来非常相似的词。笑话问题是不允许的。