jQuery interview questions and answers – Part2
11. Why should you use jQuery?
“To make web pages better” is the right answer, but your interviewer is probably looking at something more nuanced like a list of key jQuery features and advantages, such as:
• jQuery simplifies client-side scripting (read: front-end development) without adding to page bloat.
• jQuery is easy to use; it is possible to include advanced jQuery features without knowing how to code thanks to countless existing plugins.
• Widespread community support. It is also supported by most major platforms.
• Free, open-source. jQuery is released under the flexible MIT License.
• Built-in AJAX capabilities, creating animations, applying CSS and event detection.
• Supported across virtually all modern browsers.
It helps to
• Improve the performance of the application
• Develop most browser compatible web page
• Implement UI related critical functionality without writing hundreds of lines of codes
• Extensible – jQuery can be extended to implement customized behavior
Other advantages of jQuery are
• Simple and Cleaner code, no need to write several lines of codes to achieve complex functionality.
• Used to develop browser compatible web applications
• Improve the performance of an application
• Very fast and extensible
• UI related functions are written in minimal lines of codes
13. What do you need to start using jQuery?
Simple: a reference to the jQuery library. The best way to do this is to add a link toGoogle’s jQuery developer library in your <head> or before the </body> tag*. This makes sure that you always have the latest version of the jQuery library, and also helps improve page speed.
14. What are the advantages of using jQuery?
• It has AJAX capabilities
• Easy to learn, use and expand
• Great built-in methods
• From the definition, it is cross-browser.
• Makes DOM Manipulation and Traversal easier.
• It has the ability to keep the code simple, readable, clear and reusable.
• It would eradicate the requirement for writing complex loops and DOM scripting library calls.
• One can easily provide effects and can do animations.
• Applying / Changing CSS.
• Cool plugins.
• Ajax support
• DOM selection events
• Event Handling
15. Is jQuery a client-scripting or server-scripting library?
jQuery is used for client-scripting.
16. Can you use other client-scripting libraries alongside jQuery?
Yes you can. You can achieve this by using jQuery.noConflict() function to avoid any conflicts resulting from the use of $() by other libraries.
17. What is a Content Delivery Network (CDN)?
A large distributed system of servers deployed in different data centers across the internet. Normally intended to serve content to end-users with high availability and performance.
18. How to load jQuery from CDN?
Below is the code to load jQuery from all 3 CDNs.
Code to load jQuery Framework from Google CDN
Code to load jQuery Framework from Microsoft CDN
Code to load jQuery Framework from jQuery Site(EdgeCast CDN)
19. How to load jQuery locally when CDN fails?
It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen.
Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.
It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.
20. Which are the popular jQuery CDN? and what is the advantage of using CDN?
There are 3 popular jQuery CDNs.
1. 1. Google.
2. 2. Microsoft
3. 3. jQuery.
Advantage of using CDN:
• It reduces the load from your server.
• It saves bandwidth. jQuery framework will load faster from these CDN.
• The most important benefit is it will be cached, if the user has visited any site which is using jQuery framework from any of these CDN