A list of top frequently asked Javascript interview questions and answers are given below.
jQuery is not a programming language but a well written JavaScript code. It is a JavaScript code, which do document traversing, event handling, Ajax interactions and Animations for web development. It is designed to to change the way we write javascript. It is a built library for javascript.
JQuery needed for:
$ symbol defines the replacement of the jquery. In the place of $ you may use jquery. It indicates the line is used for jquery.
Since $ has no special meaning in JavaScript, it is free to be used in object naming. In jQuery, it is simply used as an alias for the jQuery object and jQuery() function.
However, jQuery has no monopoly on use of $, so you may encounter situations where you want to use it in conjunction with another JS library that also uses $, which would therefore result in a naming conflict. jQuery provides the jQuery.noConflict() method for just this reason. Calling this method makes it necessary to use the underlying name jQuery instead in subequent references to jQuery and its functions.
<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
$.noConflict();
// Code that uses other library's $ can follow here.
</script>
Alternatively, you can also use a closure instead of the $.noConflict() method; e.g.:
(function ($) {{"{"}}
// Code in which we know exactly what the meaning of $ is
} (jQuery));
No, jQuery HTML only works for HTML documents not for XML Documents.
Some of the effects methods are:
Show
$(document).ready(function(){{"{"}} $("#hide").click(function(){{"{"}} $("p").hide(); });
Hide
$(document).ready(function(){{"{"}} $("#show").click(function(){{"{"}} $("p").show(); }); });
Toggle
$(document).ready(function(){{"{"}} $("button").click(function(){{"{"}} $("p").toggle(); }); });
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.
jQuery is a library of JavaScript file and it consists of DOM, event effects and the Ajax functions. jQuery is said to be a single JavaScript file.
Mac, Windows and Linux are more compatible with the jQuery.
Download the jQuery library from jQuery.com and include that reference in the asp.net page.
The command $.ui.version returns jQuery UI version.
Find method is used to find all levels down the DOM tree but children find single level down the DOM tree.
A ‘ jQuery connect’ is a plugin used to connect or bind a function with another function. Connect is used to execute function from any other function or plugin is executed.
Connect can be used by downloading jQuery connect file from jQuery.com and then include that file in the HTML file. Use $.connect function to connect a function to another function.
jQuery uses features like Sliding, File uploading and accordian in web applications.
The jQuery filter is used to filter the certain values from the object list based on the criteria. Example is to filter certain products from the master list of products in a cart website
QUnit is used to test jQuery and it is very easy and efficient.
CDN is abbreviated as Content Distribution network and it is said to be a group of companies in different location with network containing copies of data files to maximize bandwidth in accessing the data.
Method chaining is a feature of jQuery that allows several methods to be executed on a jQuery selection in sequence in a single code statement. For example, the following snippets of code are equivalent:
Without chaining:
$( "button#play-movie" ).on( "click", playMovie );
$( "button#play-movie" ).css( "background-color", "orange" );
$( "button#play-movie" ).show();
With chaining:
$( "button#play-movie" ).on( "click", playMovie )
.css( "background-color", "orange" )
.show();
jQuery.ajax() is the all-encompassing Ajax request method provided by jQuery. It allows for the creation of highly-customized Ajax requests, with options for how long to wait for a response, how to handle a failure, whether the request is blocking (synchronous) or non-blocking (asynchronous), what format to request for the response, and many more options.
jQuery.get() is a shortcut method that uses jQuery.ajax() under the hood, to create an Ajax request that is typical for simple retrieval of information. Other pre-built Ajax requests are provided by jQuery, such as jQuery.post(), jQuery.getScript(), and jQuery.getJSON()
The .detach() and .remove() methods are the same, except that .detach() retains all jQuery data associated with the removed elements and .remove() does not. .detach() is therefore useful when removed elements may need to be reinserted into the DOM at a later time.
The document.ready() event occurs when all HTML documents have been loaded, but window.onload() occurs when all content (including ../images) has been loaded. So generally the document.ready() event fires first.
Both prop() and attr() are used to get or set the value of the specified property of an element attribute, but attr() returns the default value of a property whereas prop() returns the current value.
A jQuery plugin is simply a new method that we use to extend jQuery's prototype object. By extending the prototype object you enable all jQuery objects to inherit any methods that you add. As established, whenever you call jQuery() you're creating a new jQuery object, with all of jQuery's methods inherited.
The idea of a plugin is to do something with a collection of elements. You could consider each method that comes with the jQuery core a plugin, like .fadeOut() or .addClass().