Valid JavaScript variable names

  • Whilst this is a good novelty, please please please don't do this - ever!

    As my father said "just because you can put your penis in a goat, doesn't mean you should".

  • An Identifier is an IdentifierName that is not a ReservedWord.

    In .NET CLR languages, you can use Unicode for identifiers like in JS, but an interesting side-effect of the 'common' aspect of the CLR is that you can use reserved keywords too. This is because reserved words in one language are not necessarily reserved words in another language.

    Someone could write the following valid definition in VB.NET:

       Public Property ushort() AS Integer
    
    And because it's a reserved keyword in C# you'd have to reference it using the '@' escape:

       foo.@ushort = 123;
    
    (There are probably far more confusing examples than this)

  • For any one curious, 'ಠ' is pronounced as 'Ta' (Kannada language) :)

  • The most legitimate use for this is for top-level namespaces, which need to be short or they'll junk up your code like crazy. jQuery already took $, and Underscore took _. Maybe 木, ϗ, _⃗, 个, î, 人, Ǝ (not ∃, that's illegal!), ℵ, 二, ℜ, 龍, ℕ, 八, Δ, 大, ʃ, ː, 卐, or as mentioned below, λ? ˀ is probably too obnoxious though.

    For no particularly good reason, ☺ and ☠ are illegal. I think the Plan9 strategy of considering non-ASCII characters as identifier characters by default is probably a better one than changing the language grammar every time the Unicode standard revs.

    (As mentioned in another comment, http://canonical.org/~kragen/setting-up-keyboard.html https://github.com/kragen/xcompose. The Chinese I copied and pasted from http://www.mdbg.net/chindict/chindict.php?page=radicals though.)

  • > Browsers support identifiers that unescape to a reserved word, so long as at least one character is escaped using a Unicode escape sequence.

    i smell new xss exploits....

  • So who creates the λ functional JavaScript library?

  • It's a valid ruby method name!

      def ಠ_ಠ
        puts 'i like turtles'
      end

  • The tutorial about "How to write unmaintanable code" would love this. They already have some hints about putting accents on "int i" and other subtileties like that

    http://thc.org/root/phun/unmaintain.html

  • For those who like SQLite, it allows you to create tables and columns with zero length names (you have to quote) and it does indeed work correctly when you use them. This is valid:

    CREATE TABLE ""("" "");

    A zero length table name with one column with a zero length name having a type of a zero length name.

  • Works fine in PHP as well:

      php > $ಠ_ಠ = 1;
      php > echo $ಠ_ಠ;
      1
    
      php > $π = pi();
      php > echo $π;
      3.1415926535897931159979634685442
    
      php > function ಠ_ಠ() { echo 1; }
      php > ಠ_ಠ();
      1

  • Works in C# as well...

  • Yup, it does indeed work. http://jsfiddle.net/bJAed/

  • why shouldn't it be?

  • Because it's awesome!