Why does JQuery have dollar signs everywhere?

Jquery

Jquery Problem Overview


I am working on a project with quite a lot of JQuery in it. The JQuery has a lot of $ signs everywhere, for example

$(document).ready(function () {
        $('input[type=file]').wl_File({
            url: '/Admin/PolicyInventory/UploadDocuments',
            onFileError: function (error, fileobj) {
                $.msg('file is not allowed: ' + fileobj.name, {
                    header: error.msg + ' Error ',
                    live: 10000
                });
            }
        });
...

My question is, what does this dollar sign mean? Why is it used all over the place and how do I understand and interpret it? It reminds me of the scary days of when I was learning Scheme at University and had to put brackets everywhere without knowing why I was doing it.

Jquery Solutions


Solution 1 - Jquery

$ is just a shortcut for jQuery. The idea is that everything is done with the one global symbol (since the global namespaces is ridiculously crowded), jQuery, but you can use $ (because it's shorter) if you like:

// These are the same barring your using noConflict (more below)
var divs = $("div");       // Find all divs
var divs = jQuery("div");  // Also find all divs, because
console.log($ === jQuery); // "true"

If you don't want to use the alias, you don't have to. And if you want $ to not be an alias for jQuery, you can use noConflict and the library will restore $ to whatever it was before jQuery took it over. (Useful if you also use Prototype or MooTools.)

Solution 2 - Jquery

$ sign is an alias for jQuery. A short version of jQuery, a less write mechanism.

Just for an example: (in jQuery it's more complicated)

var yourFunction = function() {
    alert('a function');
}

window.Myf = yourFunction;

Now you can call yourFunction like:

Myf(); // definitely a short syntax

Solution 3 - Jquery

It's just a convenient character, shorter to type and easier to read than "jQuery".

There is nothing special except that it's traditionally not used to start a variable or function name, which reduces the risk or name collision.

Solution 4 - Jquery

Writability and Performance


When we are working on library or a programming language we should pay attention to some writability rules. Thanks to jQuery they already implemented lots of options. You can use $ or you can use jQuery or you can use _

(function (_) {
    _("#wow").click()
})(jQuery);

Or maybe you can do fancy changes, javascript identifiers are unicode so you can use Ω

(function (Ω) {
    Ω("#wow").click()
})(jQuery);

But the main idea behind it, pressing once to the keyboard is better than typing jQuery


On the other side, we have performance... I just randomly opened one of my projects and searched for $, I used 54 $ in a single javascript file.

$ is a byte.

jQuery is 6 bytes.

The difference is huge 54 * 5 = 220 bytes.

Solution 5 - Jquery

Google is your friend: $ sign JQuery

Dollar Sign is just an alias for JQuery.

jQuery(document).ready(function(){});

OR

$(document).ready(function(){});

Solution 6 - Jquery

In javascript, $ (a single dollar character) is a valid variable name. Several frameworks, among which jQuery, have adopted it as a synonym of an object that contain the top-level convenience methods the framework provides.

Solution 7 - Jquery

$ sign is used as an alias to Jquery. instead of using jquery.hide,jquery.show every where we can use the alias $ ($.hide) Since we are using this word lot of times. 'Jquery' will not be a convenient way so we are using the alias $. If we want to change it we can change it by noConflict method var Sample=$.noConflict()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSachin KainthView Question on Stackoverflow
Solution 1 - JqueryT.J. CrowderView Answer on Stackoverflow
Solution 2 - JquerythecodeparadoxView Answer on Stackoverflow
Solution 3 - JqueryDenys SéguretView Answer on Stackoverflow
Solution 4 - JqueryAhmet Can GüvenView Answer on Stackoverflow
Solution 5 - JqueryKashifView Answer on Stackoverflow
Solution 6 - JqueryConfusionView Answer on Stackoverflow
Solution 7 - JqueryLijoView Answer on Stackoverflow