I noticed that several JavaScript IDEs (e.g. Sublime) show the word java
with a syntax highlighting like it is a reserved keyword.
Also older versions of Firefox have problems with a function called java.
function java() {
alert("This function can not be called");
}
Is this actually a keyword? If yes what is it for?
Ultimately the answer is it is not a reserved keyword, you should be safe in using java
as a variable name.
But as noted on http://www.javascripter.net/faq/reserved.htm it states that java
is one of the words that should have been reserved words. And I believe the reasoning he is referring too is for Java Applet integration.
It is hard to find references of this on the web because the technology is largely deprecated. It appears that up until Firefox 16 Mozilla included Globals for Packages
, java
, and netscape
(See 2.1.5 Deprecated Functionality: the Global Packages, java and netscape Keywords)
The only bits of this I could find are referenced in Mozilla's LiveConnect Documentation where you can see in Java in Firefox Extensions First the note
Note: The global java object has been removed in Gecko 16.0, so this page is out of date
And then the sample code block:
var aJavaList = new java.util.LinkedList();
So basically before Mozilla had deprecated the global java
object (and possibly applets were on the page?), this could have been a problem.
Well, it's not actually Java keywords, as Javascript doesn't have anything to do with Java except borrowing the name.
The names were reserved in case they would be needed in future expansions of the language. From the ECMAScript Language Specification:
The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions...
http://www.javascripter.net/faq/reserved.htm
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