3

Possible Duplicate:
what is the meaning of "$" sign in javascript

If Jquery is just external javascript code, then how does it use the dollar sign? Wouldn't that be adding new syntax?

Community
  • 1
  • 1
mowwwalker
  • 16,634
  • 25
  • 104
  • 157

2 Answers2

14

$ is just a normal variable. You can do var $ = 42;.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • I didn't realize you could use dollar signs in defining variables though... I thought they had to start with a letter or underscore and could only contain letters, numbers, and underscores. – mowwwalker Aug 16 '11 at 18:47
  • You can use `$` sign pretty much anywhere in a variable name. – Dogbert Aug 16 '11 at 18:48
  • 3
    @user828584: Don't worry, yours was a [very](http://stackoverflow.com/questions/1180213/jquery-the-dollarsign) [common](http://stackoverflow.com/questions/846585/can-someone-explain-the-dollar-sign-in-javascript) [question](http://stackoverflow.com/questions/205853/why-would-a-javascript-variable-start-with-a-dollar-sign). – mopsled Aug 16 '11 at 18:50
2

jQuery - and any other javascript framework, simply encapsulate existing functionality in different utility functions. Most platforms endeavor to cover different browser implementations.

So, jQuery's dollar-sign operator is simply a function in which javascript functionality is encapsulated. It is, in essence, an alias for document.getElementById, but it also covers getting by class name or tag name.

As for adding new syntax, in short: no, it does not. The look and organization of code written in a framework may be different, but at the core you're still writing javascript, you're just using a set of functions provided by the library instead of using the set of functions in javascript core.

var $ = function () {
  // do something here
}
Chris Baker
  • 49,926
  • 12
  • 96
  • 115