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

  • Home
  • SEARCH
  • 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 956265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:30:56+00:00 2026-05-16T00:30:56+00:00

Hey, I was just writing another basic script for my JS & jQuery practice,

  • 0

Hey, I was just writing another basic script for my JS & jQuery practice, and I was just pumping out the goold ol’ document-ready event when I realized what this was actually comprise of, and I wanted to know if I was right or not:

Here is the document ready for jQuery:

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

Now, the dollar sign is shorthand for jQuery, which calls the jQuery library, so we can make jQuery statements and calls, correct?

The (document) is a selector that is referring to the “highest” piece of the DOM (other than Window?).

.ready is an action that occurs when the DOM is fully loaded. Now, the “DOM” being fully loaded, does the DOM in this case refer to what’s being selected? So if, body was selected instead of document, would the script executed before the loaded?

(function(){});

This part gets me a little confused.

I know that once our document has loaded, then it will run our script. In other words, it will run our function right? Is our whole script being thought of as a function? And, it’s really just one big JavaScript statement, correct? Because it ends in a semi-colon. Also, why does our script generally go between the braces, and not the parentheses of the function? What is the difference?

Thanks so much, sorry for the n00by question, I was just curious! xD

  • 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-16T00:30:56+00:00Added an answer on May 16, 2026 at 12:30 am

    Wow, that is a lof of questions for one answer 🙂

    Now, the dollar sign is shorthand for jQuery, which calls the jQuery library, so we can make jQuery statements and calls, correct?

    Yes, $ and jQuery refer to the same object. Taken from jQuery’s source:

    // Expose jQuery to the global object
    window.jQuery = window.$ = jQuery;
    

    window is the global object. Anything added to it becomes available globally, so you may call it either as window.$, or just $ for instance.

    The (document) is a selector that is referring to the "highest" piece of the DOM (other than Window?).

    document is not a selector, but a DOM object referring to the top-most node in the DOM. It has other properties such as document.domain, etc. One of its children is the <html> element.

    .ready is an action that occurs when the DOM is fully loaded. Now, the "DOM" being fully loaded, does the DOM in this case refer to what’s being selected?

    Yes, DOM refers to the items we usually select in a jQuery selector. More specifically it is the in-memory representation of the page. ready uses a bunch of events for different browsers to determine when the DOM has loaded.

    So if, body was selected instead of document, would the script executed before the loaded?

    Currently jQuery’s source code does not care what selector was passed in when you’re calling ready. Here’s the ready function:

    ready: function( fn ) {
        // Attach the listeners
        jQuery.bindReady(); 
    
        // If the DOM is already ready
        if ( jQuery.isReady ) {
            // Execute the function immediately
            fn.call( document, jQuery );
    
        // Otherwise, remember the function for later
        } else if ( readyList ) {
            // Add the function to the wait list
            readyList.push( fn );
        }
    
        return this;
    },
    

    Since it doesn’t care about what selector is passed in, you could just as well pass it body, nothing, or anything you wish.

    $({
        an: 'object', 
        that: 'has', 
        nothing: 'to', 
        'do': 'with', 
        ready: 'event'
    }).ready(function() { .. });
    

    and it will still work.

    (function(){});

    This part gets me a little confused.

    I know that once our document has loaded, then it will run our script. In other words, it will run our function right?

    Yes, this and each function that you bind with the ready event will be executed when the DOM is ready.

    Is our whole script being thought of as a function?

    No, not the entire script. Only items that depend on the DOM. Some things need to be processed as they are found. Think about the jQuery library itself. It does not wait for any DOM ready event before getting processed. If you write a JavaScript statement, it will be processed in the order it was found unless it is a callback function like the one you pass to ready(..). So the code below will execute immediately and alert "hello" regardless of whether the DOM is loaded or not.

    <script>
        function hello() { alert("hello"); }
        hello();
    </script>
    

    And, it’s really just one big JavaScript statement, correct?

    Not really. You can modularize your JavaScript as neatly as you want. For example, you can have something akin to classes, objects, reusable widgets, architecture patterns such as MVC among a bunch of other things.

    Because it ends in a semi-colon.

    A semi-colon has nothing to do with when something gets executed. I could very well write.

    <script>
        alert("Hello"), alert("World")
    </script>
    

    which will work and alert the two words in sequence and there is no semi-colon.

    Also, why does our script generally go between the braces, and not the parentheses of the function? What is the difference?

    It’s how a function is defined in JavaScript and several other languages. Brush up your basic skills to understand better. Don’t refer to it as a script as it only confuses matters. It is just a function with some statements inside it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In most configurations I can't imagine that it would matter.… May 16, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer open up the eav_attribute table and find the row where… May 16, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer If I understand you correctly, you wanna be able to… May 16, 2026 at 6:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Hey, I've just finished writing a VB.NET application. Now I want to package the
hey im writing a c# flv2mp3 converter and i could need some help. flv
I'm interested in finding out what's the shortest script one can write to replace
Hey i am hoping to write a program where the program automatically just copy
Hey I have a really simple question that needs more of just an explanation
Hey all, weird question. My company has an application from another company that records
Hey guys, hope this isn't too much of a n00b question I'm mainly a
Hey. I'm taking a course titled Principles of Programming Languages, and I need to
Hey, I'm trying to get an extension to wait for a xml message from
Hey guys, I thought this would be fairly straightforward, but it's not it seems..maybe

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.