Without let before name - TypeError: name.map is not a function

▼魔方 西西 提交于 2021-01-29 17:54:02

问题


If I don't use let or var before allocation to my varaiable name I get a TypeError: name.map is not a function
Is name a reserved word or anything else. If so I'm wondering why I don't get any error at the allocation name = [ ... ];
Can anybody give me some more information about this behaviour.

name = ["apple", "orange", "strawberry", "banana"];
result = name.map(elem => elem.toUpperCase() );
console.log(result);

If I put let or var before it works as desired.

let name = ["apple", "orange", "strawberry", "banana"];
result = name.map(elem => elem.toUpperCase() );
console.log(result);

By all other variable-names the global use of it isn't any problem although usually better to avoid.

other = ["apple", "orange", "strawberry", "banana"];
result = other.map(elem => elem.toUpperCase() );
console.log(result);

来源:https://stackoverflow.com/questions/63450022/without-let-before-name-typeerror-name-map-is-not-a-function

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