名为“name”时的Javascript数组变量在存储字符串时显示意外结果

名为“name”时的Javascript数组变量在存储字符串时显示意外结果,javascript,arrays,variables,variable-names,Javascript,Arrays,Variables,Variable Names,我正在编写一个非常简单的代码,用于将字符串存储在数组中,然后将其拆分,但显然变量名似乎对结果有影响 我已经在谷歌Chrome控制台和微软edge上试过了。结果是一样的 var fullName=乔纳森·阿彻; var name=fullName.split; console.logname[0]; //上述代码的输出为:J var userName=fullName.split; console.loguserName[0]; //上述代码的输出为:Jonathan //也试过跟随,也表现出与

我正在编写一个非常简单的代码,用于将字符串存储在数组中,然后将其拆分,但显然变量名似乎对结果有影响

我已经在谷歌Chrome控制台和微软edge上试过了。结果是一样的

var fullName=乔纳森·阿彻; var name=fullName.split; console.logname[0]; //上述代码的输出为:J var userName=fullName.split; console.loguserName[0]; //上述代码的输出为:Jonathan //也试过跟随,也表现出与上面相同的行为 变量名称=[Jonathan,Archer]; var userName=[Jonathan,Archer]; console.logname[0]; console.loguserName[0] 不要使用name作为变量名,因为它会与

var fullName=乔纳森·阿彻; var n=fullName.split; console.logn[0]; //上述代码的输出为:J var userName=fullName.split; console.loguserName[0]; //上述代码的输出为:Jonathan //也试过跟随,也表现出与上面相同的行为 变量n=[乔纳森,阿切尔]; var userName=[Jonathan,Archer]; console.logn[0];
console.loguserName[0];或者不要使用var,使用let或consor,或者不要在全局中使用它scope@Olian04当然:但若OP并没有使用不支持let和的环境呢const@Bergi是的:但我会使用名称以外的名称:这意味着名称在全局范围内受到限制。谢谢大家