Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the `name` keyword in JavaScript?

Tags:

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?

like image 746
Joey Adams Avatar asked Apr 18 '10 20:04

Joey Adams


People also ask

What is name keyword in JavaScript?

'name' is the property of the window object of the browser. It is a built-in property in JavaScript.

How many keywords are used in JavaScript?

The three keywords var , let , and const work around these scopes.

Why JavaScript name is JavaScript?

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.

Is an example of a JavaScript keyword?

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 .


2 Answers

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.

like image 55
James Westgate Avatar answered Dec 22 '22 08:12

James Westgate


(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.

like image 45
Katarot Avatar answered Dec 22 '22 09:12

Katarot