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
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
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
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:
<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
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.
5. What should be the type of script_url?
a) Object
b) String
c) Array
d) Any of the mentioned
View Answer
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
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.
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
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
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.
9. What is the type of datatype the async attribute optionally accepts?
a) Integer
b) String
c) Boolean
d) Decimal
View Answer
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
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.
- Practice MCA MCQs
- Check Programming Books
- Apply for Computer Science Internship
- Practice Information Science MCQs
- Check JavaScript Books