JavaScript Questions & Answers – Lazy Loading – II

This set of JavaScript Questions and Answers for Entrance exams focuses on “Lazy Loading – II”.

1. What is the initial step to set up a CSS Lazy Loading?
a) Fetching data
b) Loading the script
c) Loading the page
d) Adding the event listener
View Answer

Answer: a
Explanation: The loading attribute allows a browser to defer loading offscreen images and iframes until users scroll near them. The CSS Lazy Loading is begun with fetching the JavaScript and the CSS files.

2. What is being done in the following JavaScript code?

<script>
if (window.attachEvent)
window.attachEvent('onload', fetch);
else
window.addEventListener('load', fetch, false);
</script>

a) Event and EventListener is created according to the if-else
b) The values are updated
c) The value is called
d) The values are stored
View Answer

Answer: a
Explanation: In the above code, the event is attached with onload and the fetch function is called. Also, the event listener is created and added if the “if” fails and is stored as load and the fetch function is called.
advertisement
advertisement

3. What is the purpose of holding whatever tag you create in the attribute type?
a) To have more information
b) To identify the scripting language
c) To store data
d) To store variable name
View Answer

Answer: b
Explanation: A variable is created to hold whatever tag you create, and then branch the logic based on the value of type, which identifies it’s for JavaScript or for CSS. Hence, the attribute acts as an identifier to the tag.
Note: Join free Sanfoundry classes at Telegram or Youtube

4. What does the appendChild() method perform?
a) Appends a node in the middle of the index taken as the parameter
b) Appends a node as the first child
c) Appends a node as the last child
d) Replaces and appends at the last node
View Answer

Answer: c
Explanation: The appendChild() method appends a node as the last child of a node. You can also use this method to move an element from one element to another.

5. What is being done in the following JavaScript code?

advertisement
<script>
function fetch()
{
   remoteLoader.loadJS("/lab/perfLogger.js", init)
   remoteLoader.loadCSS(["/style/base.css", 
   "http://fonts.googleapis.com/css?family=Metrophobi
   c&amp;v2"])
}
</script>

a) JS and CSS files are deleted
b) CSS is replaced with JS
c) JS is replaced with CSS
d) JS and CSS files are loaded
View Answer

Answer: d
Explanation: In the above function, the JavaScript and the CSS files are loaded remotely. The loadURls method returns a promise which will receive the temporary folder as an argument.
advertisement

6. What should be the value of the type attribute of a variable if the type of file is CSS?
a) text/js/css
b) text/js
c) text/css
d) text
View Answer

Answer: c
Explanation: Since the type of file is CSS, the type attribute should hold the value text/css. For javascript file type attribute would hold the vale text/js.

7. How to lazy load images?
a) Remove the rel attribute
b) Remove the src attribute
c) Make rel = src
d) Make src = rel
View Answer

Answer: b
Explanation: The way we would lazy load images would be to alter the HTML of the page to remove the contents of the src attribute of each image. We could just move the contents of the src attribute to an attribute in the image tag of our own design, maybe the rel attribute.

<img src="#" rel="[path to image]" />

8. What does the rel attribute of a variable have when the type of file is CSS?
a) css
b) stylesheet
c) text/css
d) plainsheet
View Answer

Answer: b
Explanation: A web style sheet is a form of separation of presentation and content for web design in which the markup (i.e., HTML or XHTML) of a webpage contains the page’s semantic content and structure, but does not define its visual layout (style). The rel attribute must hold the value rel = ‘stylesheet’.

9. What is the parameter of the method getElementsbyTagName() if we need to get an image?
a) image
b) src
c) img
d) imageurl
View Answer

Answer: c
Explanation: To get the source attribute the parameter is src. The method must look like getElementsbyTageName(“img”) if we need to get an image.

10. How do we stop blocking of loading and executing the perfLogger, a logging type data?
a) Inlining the perfLogger
b) Removing the perfLogger
c) Placing the perfLogger before the “script” tag
d) Placing the perflogger after the “script” tag
View Answer

Answer: a
Explanation: A performance logging tool that provides file logging with timestamp and memory usage statistics. On calling End() a csv file of logged items will be generated. By inlining the perfLogger, we no longer block the loading and executing of it.

Sanfoundry Global Education & Learning Series – Javascript Programming.

To practice all areas of JavaScript for Entrance exams, here is complete set of 1000+ Multiple Choice Questions and Answers on Javascript.

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.