In Javascript, everything is data, this includes function. As a contrived example:
function test() {
console.log("test");
}
For this example, test()
is the invocation of the function. Simply using test
is like using a variable which allows you to do something like:
var t = test;
t();
Which then causes t
to have the same data/functionality as test
.
This then allows you to do something like a closure:
function closure() {
var i = 0;
function inner() {
i++;
console.log(i);
}
return inner;
}
Since a function is just some data, we can return it and then invoke it. So you would then write something like:
var t = closure();
t(); // prints '1'
t(); // prints '2'
Among other benefits, doing this allows you to keep your namespace a bit less cluttered.
To directly answer your question, $
is just an alias for jQuery
which was made by doing:
function jQuery() { /* Lots of code */ }
$ = jQuery;