1.

Why do we need to use an onload event in the script tag after using the async attribute?(a) Invoke code during page loading(b) Invoke code during script loading(c) Invoke code during downloading(d) Invoke code during reloadingI got this question in a job interview.Asked question is from Script Loading in section Invocation and Performance Navigation of JavaScript

Answer»

The correct answer is (c) INVOKE code during downloading

Easy explanation: When using ASYNC you don’t KNOW when the FILE will be downloaded, so you can attach an onload event handler to the script tag. This will allow you to invoke or INSTANTIATE any code that will need to be run when the file is downloaded:



Discussion

No Comment Found

Related InterviewSolutions