JavaScript Questions & Answers – Script Loading – I

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Script Loading – I”.

1. What is the purpose of script loading?
a) Load Scripts programmatically
b) Load JavaScript files manually
c) Load JavaScript files programmatically
d) Load Scripts programmatically & manually
View Answer

Answer: c
Explanation: The script loading loads remote JavaScript files programmatically and allow us to trick the rendering engine. The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available.

2. What will happen if the browser encounters a script tag without an src attribute?
a) Throws an error
b) Throws an exception
c) Sends it to the compiler
d) Sends it to the interpreter
View Answer

Answer: d
Explanation: If the browser encounters a script tag without an src attribute, the rendering engine simply passes the code to the JavaScript Interpreter for execution. The src attribute specifies the location (URL) of the external resource.

3. What is the solution to the absence of a script tag without an src attribute?
a) Resend the scripts
b) Create inline JavaScript
c) Attach a javascript file
d) Include a file
View Answer

Answer: b
Explanation: The solution to the absence of a script tag without an src attribute is to create inline JavaScript to append script tags to the document dynamically, for example:

advertisement
advertisement
<script>
var script = window.document.createElement('SCRIPT');
script.src = src;
window.document.getElementsByTagName('HEAD')[0].appendChild(script);
</script>

4. How to get a particular value using the tagged name?
a) getElementbyID()
b) getElementsbyName()
c) getElementsbyTagName()
d) getTagName()
View Answer

Answer: c
Explanation: The getElementsByTagName() method returns a collection of all elements in the document with the specified tag name, as a NodeList object. The method getElementsbyTagName() can be used to get a particular value using the tagged name associated with the document.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

5. What should be the type of script_url?
a) Object
b) String
c) Array
d) Any of the mentioned
View Answer

Answer: d
Explanation: The type of script_url can be anything that will be compared with the typeof keyword’s result. The src attribute specifies the location (URL) of the external resource.

6. What is the purpose of using the async attribute in the script tag?
a) Load the script asynchronously
b) Load the script synchronously
c) Load the page asynchronously
d) Load the page synchronously
View Answer

Answer: a
Explanation: The async option is a native attribute that will tell the browser to load the script asynchronously. The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available.
advertisement

7. 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 reloading
View Answer

Answer: c
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:

<script src="[URL"] async onload="init();]"></script>

8. What is the purpose of the startTimeLogging() method?
a) Start the timer
b) Capture time logging
c) Capture timing data for referencing
d) All of the mentioned
View Answer

Answer: d
Explanation: The startTimeLogging() method captures the timing data for ad hoc, etc for referencing an uncached document.location. Once the startTimeLogging() method is called, run the code to test.
advertisement

9. What is the type of datatype the async attribute optionally accepts?
a) Integer
b) String
c) Boolean
d) Decimal
View Answer

Answer: c
Explanation: The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available. The async attribute optionally accepts the boolean datatype of default value as true.

10. What is the method used to create an element in the HTML DOM?
a) createDOMelement()
b) createElement()
c) createDOMElement()
d) create()
View Answer

Answer: b
Explanation: The createElement() can be used to create an element in the HTML DOM. After the element is created, use the element.appendChild() or element.insertBefore() method to insert it to the document.

Sanfoundry Global Education & Learning Series – Javascript Programming.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.