Javascript - $ Symbol

This is a question for me when I am working with JQuery. What is a $.XXX function? Is $ a variables or object?

In Javascript, $ is commonly use as a short hand for variable definition and function declaration. In layman term, it is just a name.

Javascript variables must start with a letter, underscore or dollar sign.

Thus, we can have a function variable like

var $ = function(){
          alert("$ function");
}

Then, you can call this function as $()

 onclick="$()"

Now, back to jQuery, by default, jQuery uses $ as a shortcut for "jQuery"

That means

jQuery('div.foo'); === $('div.foo');

More readings:

http://www.authenticsociety.com/blog/JavaScript_DollarSign
http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Comments

Popular Posts