+ 2

Onload vs Invoke in JavaScript

Todays burning question is what is difference between invoking and onloading 1. Example invoking sololearn(); function sololearn (){ Alert("Cool'); } 2. Example Onload <body onload="sololearn ()"> <script> sololearn(){ Alert("cool"); } </script> </body>

6th Aug 2019, 3:20 AM
CoderBittu
CoderBittu - avatar
1 Antwort
+ 8
In the first example the function sololearn() is declared and called by it's name, hence it will be executed since you called (invoked) it and the code inside it will run. In the second example the declared function is set in a way that it will be executed when the body is loaded, this approach is different from invoking. If the body element is not been loaded it will not execute that function, but in the first example the function will execute since it is called by its name and do not depend on other element to load.
6th Aug 2019, 4:13 AM
Gurpreet Jhamat
Gurpreet Jhamat - avatar