问题
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