Hi,

I see in many places a $ sign before variable names in javascript. What does that $ sign mean?
For ex: i have say like below mentioned code:

Fact_Class.prototype.intz=function($n){}

What does the $ symbol before variable 'n' signify there? Can anyone explain?

Thanks,
VC

VC,

$ is one of many non-alphabetic characters that can be used in any position in ECMAScript (javascript) variable names. It is also one of a reduced set of characters that can be used in the start position.

The full rules which dictate what is legal are complex and far more liberal than you might imagine - see Section 7.6 of the ECMA-262 Standard.

Why any particular programmer chooses to use a $ (in the start position or elsewhere) is up to him/her.

When using the jQuery and Prototype libs, it is not untypical to employ variable names starting with $ to represent a jQuery/Prototype object but this is not a hard and fast rule, just convention.

Airshow

$ and _
are two (and only) non-alpha characters that don't have any special or reserved meaning in js and are safe for use in names or for names as single char pointers or as leading ones. So the choice is more like a matter of convenience -using $ or _ as a single char pointer is less likely to be overwritten spontaneously by the coder compared to other regular letters like s, o, e or i. Yet, more procedural coders will $name or _name for reading semantics where $name would indicate that it's a name of a string value and/or _name to be some sub-property object or a derivative of some other higher level object etc.
They are left in reserve by the language, but with all the guys fleeing from static languages (and who until recently openly despised the live or dynamic script) yet being heard and having their say in js standards -who knows what future might bring.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.