+ 2

Why I should call function at first;

This code I collected from w3School. can you tell me why function call at first? https://code.sololearn.com/W8NqXsSMIpkQ/?ref=app

16th Sep 2017, 6:44 AM
ARB
ARB - avatar
4 ответов
+ 7
not necessary. you have delayed your JavaScript code till doc load. so just call the function after that, it will work. does not matter if you call your function 1st or later try for yourself and see . note: the function call must be inside the onload function else your call will come before your function is loaded.
16th Sep 2017, 7:57 AM
Lord Krishna
Lord Krishna - avatar
+ 3
It ensures that Javascript works AFTER the HTML is loaded else it will produce an error not being able to find the tag you are asking for
16th Sep 2017, 6:52 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
0
In this case it doesn't matter where to call the function.
16th Sep 2017, 7:55 AM
Siroj Samadov
Siroj Samadov - avatar
0
It’s not necessary to call function at first you can call at anytime
1st Oct 2017, 1:24 PM
Naren
Naren - avatar