Piyush Sharma
Piyush Sharma

Reputation: 113

Script Execution flow in Javascript

$(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

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

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

Related Questions