What is the global variable called 'name' in javascript? [duplicate]

时间秒杀一切 提交于 2019-11-29 16:40:36

Most "globals" in JavaScript when running in a browser are actually properties of the window object (of type Window).

But Window already has a name property, so any attempt to assign a non-string to it is going to lead to conversion to a string: the type of the assigned object will not be maintained.

While name by itself is a property of the window object, you may still use name with another object as follows:

var obj2 = { "s1": "spring", "s2": "summer", "s3": "fall", "s4":"winter"};

obj2.name = obj2["s4"];
console.log("Name: " + obj2.name);

obj2.favoriteWeather = obj2.name;
console.log("Favorite season: " + obj2.favoriteWeather);

Resource: MDN Talk: Reserved_Words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!