Question: I have following jquery code in client side JS

```
// Following gets executed at document.ready() time

    $(function() {
      prepareCurList();
    });

// When does the following code gets executed as its just a plain JS statement???

    prepareNextList();

```

Please provide pointers.

Answer: 
The following code is executed right after executing `$(function() { })`. 

`$(function () {})` is just **registering** a handler to be executed on document ready, but the handler itself will not be executed until document is ready.
The Javascript is DOM independant. When your browser parse a web page, it will handle the HTML part and load it in the DOM (in memory) while the javascript part will be directly given to the Javascript machine of the browser.

The javascript machine will directly execute the Javascript code without waiting for anything (That's why direct code will be directly eecuted when it is parsed), except if you ask it. That why you have some event handler on "load" etc.. (old basic way)

JQuery help us with the "ready" method.

Writting :

```
$(function() {

    // SOme of your code

});

```

is the same as :

```
$(document).ready(function() {

    // Some of your code

});

```

And all your code will be execute only after the DOM is loaded and ready to be used.