Jul 26, 2015

jQuery Interview Questions - Part 2

Q: Name some of the methods of JQuery used to provide effects?
Some of the common methods are :
  • Show() 
  • Hide() 
  • Toggle() 
  • FadeIn() 
  • FadeOut() 
Q: What is CDN?
CDN Stands for Content Distribution Network or also called Content Delivery Network is a group of computers placed at various points connected with network containing copies of data files to maximize bandwidth in accessing the data. In CDN a client access a copy of data nearer to the client location rather than all clients accessing from the one particular server. This helps to achieve better performance of data retrieval by client.

There are two leading CDNs available that hosts jQuery files.
Microsoft - To load jQuery from Microsoft AJAX CDN
<script type="text/javascript" language="Javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js">
Google - To load jQuery from Google Libraries API
<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">

Q: How JavaScript and jQuery are different?
JavaScript is a language While jQuery is a library built in the JavaScript language that helps to use the JavaScript language.

Q: Can we have multiple document.ready() function on the same page?
Yes. We can have any number of document.ready() function on the same page.

Q: What is jQuery.noConflict?
As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced 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: Is there any difference between body onload() and document.ready() function?
document.ready() function is different from body onload() function for the following reasons:
  • We can have more than one document.ready() function in a page where we can have only one body onload 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: 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: What are the fastest selectors in jQuery?
ID and element selectors are the fastest selectors in jQuery.

Q: What are the slow selectors in jQuery?
class selectors are the slow compare to ID and element.

Q: How do you check if an element exists or not in jQuery?
Using jQuery length property, we can ensure whether element exists or not.
$(document).ready(function(){
    if ($('#element').length > 0){
       //Element exists
  }
});

<< Prev Home Next >>

    Choose :
  • OR
  • To comment
No comments:
Write Comments