Hi,
I am playing with arrays in js trying to learn them.
I created on array of three elements but when I try to call one of them I get the character not a whole element. I don’t understand why this is.
Why is name[2] t and not owl ?
Thanks,
Shane
I think it’s happening because name is an html attribute and something in the console is making it a string, because a name is a string. That’s all I can come up with. I’m really just making an educated guess.
Yes that sounds correct. i was checking to see if name was a reserved word. To html attribute can not be used for variable names in js.
Thanks for your help,
Shane
you’d better avoid
the following identifiers as names of JavaScript variables.
These are predefined names of implementation-dependent JavaScript objects,
methods, or properties (and, arguably, some should have been reserved words):
So name isn’t actually a reserved word but needs to be avoided.
Thanks,
hey where did that link to jsfiddle go that someone, can’t remember who posted here? Because that didn’t see ‘name’ as a problem reserved word type. Which surely it should have.
Post #4 has been removed.
It looks like any property of the window object will cause problems. If you name your variable navigator or pageXOffset, for example, then you’ll also run into problems.
Moral of the story: Don’t use globals. Ever. You’ll run into naming clashes. Any of these variable names will be fine in some local scope.