4
$(function() {
    alert("hello World");
});
alert("hello");

Output:

first "hello" is alert /which is on line 2/ then "hello world" alerted I want to know what is the execution rule in javascript

1
  • JS is event-driven, so flow coincides with the outside triggering of pre-defined events. Commented Oct 20, 2015 at 1:49

1 Answer 1

5

This block will execute when dom is ready.

$(function() {
    alert("hello World");
});

This is similar to

$(document).ready(function(){

});

And 2nd alert doesn't wait for the dom ready.

that's why 2nd alert executes first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.