Jquery Interview Questions

Level: Freshers

Q 1 - What is jQuery?

jQuery is fast, lightweight and feature-rich client side JavaScript Library/Framework which helps in to traverse HTML DOM,

Q 2 - Why do we use jQuery?


   Due to following advantages.
  • Easy to use and learn.
  • Easily expandable.
  • Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
  • Easy to use for DOM manipulation and traversal.
  • Large pool of built in methods.
  • AJAX Capabilities.
  • Methods for changing or applying CSS, creating animations.
  • Event detection and handling.
  • Tons of plug-ins for all kind of needs.

Q 3 - What is the advantage of using minimized version of jQuery?

Efficiency of web page increases when minimized version of jQuery is used.min.js file will be more than 50% less than the normal js file. Reduction in the file size makes the web page faster.

Q 4 - Which operating system is more compatible with jQuery?

Mac, Windows and Linux are more compatible with the jQuery.

Q 5 - What are selectors in jQuery and how many types of selectors are there?

  • Name: Selects all elements which match with the given element Name.
  • #ID: Selects a single element which matches with the given ID
  • .Class: Selects all elements which match with the given Class.
  • Universal (*): Selects all elements available in a DOM.
  • Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G.
  • Attribute Selector: Select elements based on its attribute value.

Q 6 - What are the four parameters used for jQuery Ajax method?
 

The four parameters are.
  • URL – Need to specify the URL to send the request
  • type – Specifies type of request(Get or Post)
  • data – Specifies data to be sent to server
  • Cache – Whether the browser should cache the requested page
     

Q 7 - Which is the fastest selector in jQuery?
 

 ID and Element are the fastest selectors in jQuery.
 

Q 8 - What is the slowest selector in jQuery?

Class selectors are the slowest selectors in jQuery.

Q 9 - Is jQuery a library for client scripting or server scripting?

Client side scripting.

Q 10 - What does dollar sign ($) means in jQuery?

Dollar Sign is nothing but it's an alias for JQuery. Take a look at below jQuery code.
Example: $(document).ready(function(){<br /> }); <br /> Over here $ sign can be replaced with &quot;jQuery&quot; keyword. &nbsp; jQuery(document).ready(function(){<br /> });

Q 11 - Can we use our own specific character in the place of $ sign in jQuery?

Yes. It is possible using jQuery.noConflict().

Q 12 - What is jQuery.noConflict?


jQuery.noConflict(); // Use jQuery via jQuery(...) jQuery(document).ready(function(){
   jQuery("div").hide();
});   You can also use your own specific character in the place of $ sign in jQuery. var $j = jQuery.noConflict(); // Use jQuery via jQuery(...) $j(document).ready(function(){
   $j("div").hide();
});  
 

Q 13 - Is there any difference between body onload() and document.ready() function?

  • document.ready() function is different from body onload() function for 2 reasons.
  • We can have more than one document.ready() function in a page where we can have only one bodyonload function.
  • document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
     

Q 14 - What is the difference between .js and .min.js?
 

jQuery library comes in 2 different versions Development and Production/Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library file. Both the files are same as far as functionality is concerned. but .min.js is quite small in size so it loads quickly and saves bandwidth.

Q 15 - Why there are two different version of jQuery library?

jQuery library comes in 2 different versions.
  • Development 
  • Production/Deployment
     

Q 16 - Why there are two different version of jQuery library?

jQuery library comes in 2 different versions.
  • Development 
  • Production/Deployment
The development version is quite useful at development time as jQuery is open source and if you want to change something then you can make those changes in development version. But the deployment version is minified version or compressed version so it is impossible to make changes in it. Because it is compressed, so its size is very less than the production version which affects the page load time.

Q 17 - What is a CDN?

 A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.
 

Q 18 - Which are the popular jQuery CDN? and what is the advantage of using CDN?


There are 3 popular jQuery CDNs.
  1. Google.
  2. Microsoft
  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
     

Q 19 - 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 <script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script> Code to load jQuery Framework from Microsoft CDN <script type="text/javascript"
    src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">
</script>
Code to load jQuery Framework from jQuery Site(EdgeCast CDN) <script type="text/javascript"
    src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>