JavaScript Questions & Answers – Lazy Loading – I

«
»

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

1. What is the purpose of lazy loading?
a) Immediate loading is necessary
b) Loading under command
c) Immediate loading is not necessary
d) Loading after a definite interval
View Answer

Answer: c
Explanation: Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program’s operation if properly and appropriately used. Lazy loading is a kind of loading in which we don’t need our JavaScript code to be available as soon as the page loads.
advertisement

2. Where is the external JavaScript placed in the case of lazy loading?
a) After window.onload event
b) Before window.onload event
c) In the header tag
d) In the HTML tag
View Answer

Answer: a
Explanation: Lazy loading is a kind of loading in which we don’t need our JavaScript code to be available as soon as the page loads. When we don’t need our JavaScript code to be available as soon as the page loads, we can script-load our external JavaScript after the window.onload event.

3. What are the parameters of the attachEvent function?
a) Function
b) Function, Event
c) Event, Function
d) Event
View Answer

Answer: c
Explanation: The addEventListener() method attaches an event handler to an element without overwriting existing event handlers. The attachEvent function accepts two parameters: the event to attach to, and the function to invoke when the event occurs.

4. What is the result when the showPerformanceMetrics() is called before loading the remote script?
a) Throws an exception
b) Throws an error
c) It will load by itself
d) Throws an exception and It will load by itself
View Answer

Answer: b
Explanation: perflogger.showPerformanceMetrics() tells the user about the performance parameters of the script loading. If you try to make the call to perfLogger.showPerformanceMetrics() and the script hasn’t just loaded but also executed, then you will get an error.
advertisement

5. Which of the following is an attribute to the script object?
a) onclick
b) onload
c) onshow
d) onhover
View Answer

Answer: b
Explanation: The onload event occurs when an object has been loaded. The onload event occurs when an object has been loaded.

6. Which is the method used to add an event listener?
a) addEventListener()
b) addListener()
c) addEvent(Listener)
d) addListener(Event)
View Answer

Answer: a
Explanation: The addEventListener() method attaches an event handler to the specified element. The addEventListener() method is used to add an event listener to the script.

7. What is the purpose of the domLoading attribute?
a) Document exists
b) Document can load
c) Document has loaded
d) Document begins to load
View Answer

Answer: d
Explanation: domLoading is the time immediately before the user agent sets the current document readiness to ‘loading’. The domLoading attribute is used when the document begins to load.
advertisement

8. How is the render time calculated?
a) Date.Now()
b) Date.Now() – performance.timing.domLoading
c) performance.domLoading
d) Date.Now() – performance.domLoading
View Answer

Answer: b
Explanation: The rendering engine parses the HTML and the CSS and displays the parsed content on the screen. The render time is calculated as Date.Now() – performance.timing.domLoading.

9. The object whose properties are inherited by all instances of the class, and properties whose values are functions behaving like instance methods of the class, is _____________
a) Instance object
b) Constructor object
c) Destructor object
d) Prototype object
View Answer

Answer: d
Explanation: A prototype is an object that is associated with every functions and object by default in JavaScript, where function’s prototype property is accessible and modifiable and object’s prototype property (aka attribute) is not visible. The properties of the prototype object are inherited by all instances of the class, and properties whose values are functions behave like instance methods of the class.

10. You can refresh the webpage in JavaScript by using ___________
a) window.reload
b) location.reload
c) window.refresh
d) page.refresh
View Answer

Answer: b
Explanation: The reload() method is used to reload the current document.The reload() method does the same as the reload button in your browser. One can refresh the webpage in JavaScript by using location.reload.
advertisement

Sanfoundry Global Education & Learning Series – Javascript Programming.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn