Top 10 frequently asked JQUERY interview questions

Below are the top 10 Jquery questions that are frequently asked in Interviews

1.  What is JQUERY ?

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.

2 . What is difference between jQuery's ready and holdReady ?
jQuery's ready is an event which gets triggered automatically when DOM is ready while holdReady is a signal/flag to hold this triggering. holdReady was included in 1.6 version and it works only if used before the execution/triggering of ready event. Once ready event is fired, it has nothing to do. It is useful in dynamically loading scripts before the ready starts. It release ready event execution when used with a true parameter

3. How do you update ajax response with id " username"

function updateStatus() {
            url: 'updateUsrName.htm',
            success: function(response) {
             // update username

4. How do you get the text value of a selected option in JQUERY ?

<select id="proglang">
   <option value="1">Java</option>
   <option value="2">Javascript</option>
   <option value="3">Jquery</option>
   <option value="4">Visual Basic</option>
   <option value="5">Unix</option>

$("#proglang option:selected").text();

5.Name any four paremeter of Jquery ajax method

data : Specifies data to be sent to the server
url : Specifies the URL to send the request to. Default is the current page
type : Specifies the type of request. (GET or POST)
cache: A Boolean value indicating whether the browser should cache the requested pages. Default is true beforeSend(xhr): A function to run before the request is sent

5.What is $() in jQuery library?

 $() function is used to wrap any object into jQuery object, which then allows you to call various method defined jQuery object. You can even pass a selector string to $() function, and it will return jQuery object containing an array of all matched DOM elements.

6 . Difference between JavaScript window.onload event and jQuery ready function?

Main difference between JavaScript onload event and jQuery ready function is that former not only waits for DOM to be created but also waits until all external resources are fully loaded including heavy images, audios and videos.  If loading images and media content takes lot of time that user can experience significant delay on execution of code defined in window.onload event. On the other hand jQuery ready() function only wait for DOM tree, and does not wait for images or external resource loading, means faster execution. Another advantage of using jQuery $(document).ready() is that you can use it multiple times in your page, and browser will execute them in the order they appear in HTML page, as opposed to onload technique, which can only be used for a single function. Given this benefits, it's always better to use jQuery ready() function than JavaScript window.onload event.

7. How can you call a method inside code-behind using jQuery ?
We can call a method inside code-behind By $.ajax and by declaring method a WebMethod

8.What are the advantages of JQUERY ?

The main advantages to adding jQuery are :
  • browser compatibility - doing something like .attr() is much easier than the native alternatives, and won't break across browsers.
  • simplification of usually complicated operations - if you'd like to see a well written cross browser compatible version of an XHR method, take a look at the source for $.ajax - for this method alone it's almost worth the overhead of jQ.
  • DOM selection - simple things like binding events & selecting DOM elements can be complicated and differ per-browser. Without a lot of knowledge, they can also be easily written poorly and slow down your page.
  • Access to future features - things like .indexOf and .bind are native javascript, but not yet supported by many browsers. However, using the jQuery versions of these methods will allow you to support them cross browser.
9. What is the difference between onload() and document.ready() function used in jQuery

  • We can have more than one document.ready() function in a page where we can have only one body unload 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.
  • Document.ready() function is called as soon as DOM is loaded.
  • onload() function is called when everything (DOM, images)gets loaded on the page.
10. What is difference between jQuery.get() and jQuery.ajax() method?

ajax() method is more powerful and configurable, allows you to specify how long to wait and how to handle error, get() is a specialization to over ajax just to retrieve some data.

No comments:

Post a Comment

Please Provide your feedback here