Reputation: 113
$(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
Upvotes: 4
Views: 1017
Reputation: 25352
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.
Upvotes: 5