Pages

Thursday 31 January 2013

jQuery Basic Interview Objective Questions and Answers (Part 1)

jQuery Basic Interview Objective Questions and Answers (Part 1)

Here is a small list of 14 jQuery basic interview questions and answers which a web designer and developer must know who is going for technical interview of jQuery, Javascript and AJAX (UI: User Interface). Some of these jQuery interview questions are objective and some are subjective. These jQuery interview questions and answers should be on finger tips of each web designer and developer. Many basic jQuery interview questions are related to CDN (Content Delivery Network) like Google CDN, Microsoft CDN and EdgeCast CDN and some are based on jQuery selectors. Lets have a look at the following list of basic jQuery interview questions and answers.

1. Is jQuery a library for client scripting or server scripting?

jQuery is client scripting library.

2. Is jQuery a W3C standard?

jQuery is not a W3C standard.

3. What are jQuery Selectors?

Selectors are used in jQuery to find out DOM elements. Selectors can find the elements via ID, CSS, Element name and hierarchical position of the element.

4. Does the jQuery html() method work for both HTML and XML documents?

jQuery html() only works for HTML.

5. Which sign does jQuery use as a shortcut for jQuery?

$(dollar) sign.

6. What does $("div") will select?

It will select all the div element in the page.

7. What does $("div.parent") will select?

All the div element with parent class.

8. What is the name of jQuery method used for an asynchronous HTTP request?

jQuery.ajax()

9. What is CDN and what are the advantage of loading jQuery framework from CDN?

Always load your jQuery framework from Google, Microsoft or jQuery CDN(Content Delivery Network). As it provides several advantages.

1. You always use the latest jQuery framework.
2. It reduces the load from your server.
3. It saves bandwidth. jQuery framework will load faster from these CDN.
4. 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.

10. Write down the code to load jQuery Framework from Google CDN.

</script>

11. Write down the code to load jQuery framework from Microsoft CDN.

</script>

12. Write down the code to load jQuery framework from jQuery website (EdgeCast CDN).

<script  type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

13. How do you load jquery locally when CDN fails?

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. 

</script>

<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
  document.write(unescape("%3Cscript src='Scripts/jquery.1.5.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>

It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will reference the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.

14. What is jQuery.noConflict?

jQuery is great library written on top of Java Script and its popularity is increasing day by day.The reason of popularity of jQuery is the plenty of useful, simple and easy to use plugins. But while using jQuery plugins, sometimes we include other libraries like prototype, mootools, YUI etc. The problem comes when one or more other libraries are used with jQuery as they also use $() as their global function and to define variables. This situation is creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().

<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
     jQuery.noConflict();
     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     }); 
     // Use Prototype with $(...), etc.
     $('someid').hide();
</script>

When .noConflict() is called then jQuery returns $() to its previous owner and you will need to use jQuery() instead of shorthand $() function. In this case, "jQuery" will be used in rest of the code. You won't be able to take advantage of shorthand.

<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
     var $j = jQuery.noConflict();
     // Use jQuery via jQuery(...)
     $j(document).ready(function(){
       $j("div").hide();
     }); 
     // Use Prototype with $(...), etc.
     $('someid').hide();
</script>

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.