$(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
Harshal Carpenter
4881 gold badge9 silver badges26 bronze badges
asked Oct 20, 2015 at 1:44
Piyush Sharma
1131 silver badge8 bronze badges
-
JS is event-driven, so flow coincides with the outside triggering of pre-defined events.dandavis– dandavis2015年10月20日 01:49:59 +00:00Commented Oct 20, 2015 at 1:49
1 Answer 1
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.
answered Oct 20, 2015 at 1:48
Anik Islam Abhi
25.4k8 gold badges61 silver badges82 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js