Xaprb

Stay curious!

Don’t use future reserved words as identifiers in JavaScript

with 4 comments

Just a quick note: I found recently that some browsers don’t complain when I use future reserved words as identifiers in JavaScript. Specifically, I used char as a variable name, and no Windows browser had a problem with it — but when I tested on Mac, both Safari and Firefox complained. Apparently there are differences in JavaScript implementation between the Windows and Mac versions of Firefox 1.5!

Nitty-gritty details: the ECMA-262 spec defines reserved words and future reserved words in section 7.5.1. Many OO-ish keywords like implements are reserved for the future, as well as specific data types like int and … you guessed it, char.

Further Reading:

Written by Xaprb

December 23rd, 2005 at 2:20 pm

Posted in Uncategorized

4 Responses to 'Don’t use future reserved words as identifiers in JavaScript'

Subscribe to comments with RSS

  1. Confirmed, co-incidentally, with Safari 1.3. Firefox 1.5 had no problem, though.

    Bill Gates

    2 Feb 06 at 8:03 pm

  2. That’s common practice.

    Rock and Roll

    21 Jun 07 at 6:27 am

  3. Don’t forget that Netscape’s Javascript has Java compatibility baked in, so you can refer directly to things like java.util.Vector in your scripting. The implication is that all Java reserved words and top-level package names (java, javax, and sun, and probably com, org, net, and edu as well) are reserved in Netscape’s version of ECMAscript.

    Tim McCormack

    7 Mar 09 at 2:08 pm

  4. I didn’t know that!

    Xaprb

    7 Mar 09 at 2:28 pm

Leave a Reply