When I typed this apparently innocent snippet of code:
values.name
gedit highlighted name as a keyword. However, name is not listed by the pages linked to by an answer to a question about reserved keywords. I also did a couple trivial tests in SpiderMonkey, but name seemed to act like an ordinary identifier.
A Google search didn't tell me much either. However, I did find a page listing name in "Other JavaScript Keywords". My guess is that name is a function or a member of some DOM element and does not intrude on the namespace.
Is name really a keyword in JavaScript? If so, what does it do?
'name' is the property of the window object of the browser. It is a built-in property in JavaScript.
The three keywords var , let , and const work around these scopes.
The name JavaScript came from Netscape's support of Java applets within its browser. Many say it was also a marketing tactic to divert some attention from Java, which was the most buzzed-about language at the time. To run Java programs, the code must be first compiled into an executable form.
Keywords are tokens that have special meaning in JavaScript: break , case , catch , continue , debugger , default , delete , do , else , finally , for , function , if , in , instanceof , new , return , switch , this , throw , try , typeof , var , void , while , and with .
Its not a javascript reserved word, its an html attribute. Any DOM element can have a name. Looks like your syntax editor will still highlight it.
(I know this was asked 2 years ago but, ...) This happened to me also, for example this below would not work.
name = document.getElementById('nombre'); //something else name.className = 'thinking';
Instead I changed it to
username = document.getElementById('nombre'); //something else username.className = 'thinking';
and it did work! Yeah, alright that's all, but it's something I find maybe quite interesting, also because of the 'name' attribute of the 'a' tag. Something to watch out for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With