The $
sign means nothing particular in JavaScript, it is only another valid character to use in variable names.
For example you can call a variable abc
, a$b$c
, hèy
or wathever you like, there's no difference, the only thing that changes is the name of the variable:
var abc = 1,
a$b$c = 2,
hèy = 3;
console.log(abc, a$b$c, hèy); // 1 2 3
Why the dollar sign then? The dollar sign is just a shorter, more convenient name for the jQuery
function.
window.jQuery = window.$ = jQuery;
// This is usually what a jQuery library does
In fact, using the jQuery library it will happen to call jQuery(...)
several times, and writing $(...); $(...); $(...);
is much faster than writing jQuery(...); jQuery(...); jQuery(...);
. You can actually see that typing the following lines in the console of a site that uses jQuery, like Stack Overflow itself, will return a true
value:
$ === jQuery // true
$.bind === jQuery.bind // true
// and so on...
Then why do users put a $
at the beginning of variable names? Since that the common abbreviation for jQuery is the dollar sign, users tend to name variables created using jQuery with a dollar sign at the beginning, so it will be easy to know where they come from later in the code, like this:
var body = document.body,
$body = $(document.body); // equivalent to jQuery(document.body);
// Now you know that $body does have all the common jQuery collection properties, but body doesn't
Referring to your code: the $Code
variable is just an object like any other, but it has been probably created using jQuery.