3

Possible Duplicate:
Why would a javascript variable start with a dollar sign?
Can someone explain the dollar sign in Javascript?

I was looking at a js tutorial where several of the functions where declared with a $ in front of them. I have done some on-line searching but can find no reference to this. Here is an example I created myself:

var $x = function(q)
{
  return q*q;
}

var $y = function()
{
  alert($x(10));
}

When I call $y from a webpage I get an alert with 100, which is what I expect. So, what, if anything, is the $ for?

Community
  • 1
  • 1
ZeroD
  • 31
  • 1

4 Answers4

2

I don't think $ means anything special, the tutorial just decided to name the function $x and $y

awesome
  • 121
  • 3
1

It doesn't mean anything special unless you've included jQuery. Generally, I've seen $ used in the beginning of variables to mark them as global variables.

VNO
  • 3,645
  • 1
  • 16
  • 25
0

$ is one of the allowed signs for names of variables in JavaScript. It is not an operator.

As some other answer on SO mentioned, allowed characters are: [a-zA-Z_$][0-9a-zA-Z_$]*.

So, this is not an operator, and can be used to distinguish some variables from other variables.

When it comes to single dolar sign ($, without any other letter), this is common as alias for jQuery function, if you have installed jQuery and stick with default settings.

Community
  • 1
  • 1
Tadeck
  • 132,510
  • 28
  • 152
  • 198
0

In this particular case, serves no purpose. You can remove it an simply do y(10); or x(10);

For example Microsoft introduced $find as a shorthand for document.getElementById

Icarus
  • 63,293
  • 14
  • 100
  • 115