Search code examples
javascriptnaming-conventionsnaming

Starting Class or Method Names with Numbers, Why Not?


I recently was quickly shortening some method names in a JavaScript file and ran into a problem when I converted one method name:

Before:

RefreshSevenDayGrid(){
    // some stuff
}

After:

7Day() {    
    // some stuff
}

I quickly discovered that the javascript no longer worked. I heard from several people that numbers should never be used for method or class names. Is there ever an exception to this?


Solution

  • Besides what Jeffrey Hantin said, there are numeric constants such as

    3e7  // 3x10^7
    40L  // C, C++, etc for a long integer
    0x88 // hexadecimal
    

    The general convention for identifiers which is used widely in most languages, is [S except for 0-9][S]* where S is some set of valid characters (A-Z, a-z, 0-9, sometimes _, $, or -) -- so the first character can't be a digit but the rest can.