Which characters can be used for naming a JavaScript variable?
I want to create a small \"extension library\" for my non-JavaScript users here at work (who all seem
Javascript variables can have letters, digits, dollar signs ($) and underscores (_). They can't start with digits.
Usually libraries use $
and _
as shortcuts for functions that you'll be using everywhere. Although the names $
or _
aren't meaningful, they're useful for their shortness and since you'll be using the function everywhere you're expected to know what they mean.
If your library doesn't consist on getting a single function being used everywhere, I'd recommend that you use more meaningful names as those will help you and others understand what your code is doing without necessarily compromising the source code niceness.
You could for instance take a look at the awesome DateJS library and at the syntatic sugar it allows without the need of any symbol or short-named variables.
You should first get your code to be practical, and only after try making it pretty.