Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:16:35+00:00 2026-05-24T20:16:35+00:00

I have the book Jquery in Action, and it mentions these three functions when

  • 0

I have the book Jquery in Action, and it mentions these three functions when talking about removing conflict with other libraries. However, I don’t know what the difference is between them and do not understand the book’s explanation.

jQuery(function($) {
    alert('I"m ready!');
});

var $ = 'Hi!';
jQuery(function() {
    alert('$ = ' + $);
});

var $ = 'Hi!';
jQuery(function($) {
    alert('$ = ' + $);
});

Does anyone know what the difference is? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:16:36+00:00Added an answer on May 24, 2026 at 8:16 pm

    If you take a simplified version it might be more understandable. The first ready function is not doing much more than alerting. The other two are interesting.

    Functions have scope, which means that when you use a variable inside one, it will go up in the hierarchy until it has been found.

    In your second ready function, the $ will go up to the Hi! as there is no other $ if you go up starting inside the function.

    However, in the third ready block, the $ will not go to the Hi! because it has a definition that is closer – the one passed as an argument (function($) {). This $ will be the jQuery function (i.e. in that function $ == jQuery) as this is how jQuery’s ready feature is implemented.

    So:

    var $ = 'Hi!';
    
    jQuery(function() {
        alert('$ = ' + $); // in this scope, $ will refer to the 'Hi!'
    });
    
    jQuery(function($) {   // the $ here will 'shadow' the $ defined as 'Hi!'
        alert('$ = ' + $); // in this scope, $ will refer to jQuery
    });
    

    Now your question is about conflict with other libraries. Other libraries (Prototype for example) also use the $ symbol as it is a convenient shortcut to calling the library. If you use the last ready function you provided, you can be sure that inside that function, $ will refer to jQuery as jQuery passes itself to that function (as the first argument).

    In the second ready function, $ might also have been set to Prototype, for example, and you are not sure whether you are calling jQuery with $. In your example, it was Hi! and not jQuery. In case it’s Prototype it’s the same thing. Consider:

    // Prototype is loaded here, $ is referring to Prototype
    
    jQuery(function() {
        $('selector').addClass('something'); // Oops - you're calling Prototype with $!
    });
    

    On the other hand:

    // Prototype is loaded here, $ is referring to Prototype
    
    jQuery(function($) { // this $ is shadowing Prototype's $, this $ is jQuery
        $('selector').addClass('something'); // Yay - you're calling jQuery with $
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a book, Essential ActionScript 3 (O'Reilly), to learn about using that language.
I'm working through the Grails In Action book and have noticed 2 instances that
About a year ago I picked up my first HTML book (XHTML). I have
I have the following jquery code: $(document).ready(function() { $(#build_table, a.coursename, .Start Date, .Book Title,
I'm currently learning jQuery by reading jQuery in Action. The book discusses separation of
Page 146 of the jQuery mobile First look book mentions data-placeholder, but I don't
I'm trying to solve the book Rails 3 in Action where the authors have
I have a book called Statistics for Computer Scientists as well as my engineering
Anyone have good book / article recommendation for procedural generation of background music? (No
I have a book class, then a novel- and a science book class that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.