JavaScript & JQuery Interview Questions


What is Jquery?

JQuery is Java Script library or Java Script Framework which helps in how to traverse HTML documents, do some cool animations, and add Ajax interaction to any web page. It mainly helps programmer to reduce lines of code as huge code written in Java Script, can be done easily with JQuery in few lines.

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

$(document).ready(function(){

});


Over here $ sign can be replaced with "jQuery " keyword.
jQuery(document).ready(function(){

});


How is body onload() function is different from document.ready() function used in jQuery?

Document.ready() function is different from body onload() function because off 2 reasons.

1. We can have more than one document.ready() function in a page where we can have only one onload function.
2. 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.

What are the steps you need to follow to use jQuery in ASP.Net project?

It's really simple. One just need to add reference of javascript file(.js). Go to Jquery.com and download the latest version of jQuery. When download is completed, there is a "jQuery-1.3.2.js" in the folder. Include this file

<script src="_scripts/jQuery-1.3.2.js" type="text/javascript"></script>

and you good to go now for JQuery.

Note : 1.3.2 denotes the library version.. It can be vary depending upon the version of Jquery you download.

What is JQuery UI?

JQuery UI is a library which is built on top of JQuery library. JQuery UI comes with cool widgets, effects and interaction mechanism.

See below page on this site. Date Picker control used in this page to select date is an example of JQuery UI.


What are features of JQuery or what can be done using JQuery?

Features of Jquery
1. One can easily provide effects and can do animations.
2. Applying / Changing CSS.
3. Cool plugins.
4. Ajax support
5. DOM selection events
6. Event Handling

Name some of the methods of JQuery used to provide effects?

Some of the common methods are :

1. Show()
2. Hide()
3. Toggle()
4. FadeIn()
5. FadeOut()

JQuery is replacement of Java Script?

NOTE: This is objective type question, Please click question title for correct answer.

What are the different type of selectors in Jquery?

There are 3 types of selectors in Jquery
1. CSS Selector
2. XPath Selector
3. Custom Selector

What are the advantages of JQuery ?

There are many advantages with JQuery. Some of them are :

. It is more like a JavaScript enhancement so there is no overhead in learning a new syntax.

. It has the ability to keep the code simple, readable, clear and reusable.

. It would eradicate the requirement for writing complex loops and DOM scripting library calls.

How can you select all elements in a page using jQuery?

To select all elements in a page, we can use all selectors, for that we need to use *(asterisk symbol).

<script language="javascript" type="text/javascript">

         $("*").css("border", "2px dotted red"); 

</script>


The above code will select all elements of the web page and apply border width as 2 pixel, style as dotted and color as red.


Thanks and Regards
Akiii

What is jQuery?

jQuery is not a language but it is a well written JavaScript code, As quoted on official jQuery website “it is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.“

In order to work with jQuery you should be aware of basics of JavaScript, HTML and CSS.
It was released in January 2006 at BarCamp NYC by John Resig.

Licensing:
It is free, open source software Dual-licensed under the MIT License and the GNU General Public License. Microsoft has integrated jQuery officially into its IDE Visual Studio 2010 and jQuery intellisense is available in Visual Studio 2010 now.

Why jQuery?

jQuery is very compact and well written JavaScript code that increases the productivity of the developer by enabling them to achieve critical UI functionality by writing very less amount of code.

It helps to

# Improve the performance of the application
# Develop most browser compatible web page
# Implement UI related critical functionality without writing hundreds of lines of codes
# Fast
# Extensible – jQuery can be extended to implement customized behavior

Other advantages of jQuery are

# No need to learn fresh new syntax's to use jQuery, knowing simple JavaScript syntax is enough
# Simple and Cleaner code, no need to write several lines of codes to achieve complex functionality.

Where to download jQuery from?

jQuery javascript file can be downloaded from jQuery Official website

http://www.jquery.com/

How to use jQuery?

jQuery usually comes as a single JavaScript file containing everything comes out of the box with jQuery. It can be included within a web page using the following mark-up:

To load local jQuery file
<script type="text/javascript" src="jQuery-1.4.1-min.js"></script>


Ideally this markup is kept in under <head></head> tag of your web page, however you are free to keep anywhere you want.

Do I need to refer jQuery file both in Master page/base page/template page and content page?

No, master page/base page/ template page basically helps to create consistent layout for the page in the application. In case you have referred the jQuery file in master page/base page/ template page that cause rendering the file in the browser, you do not need to refer jQuery file the content page again.

In summary, there should not be more than one <script> tag with jQuery file reference in the source code of the rendered web page in the browser.

What is the difference between jQuery-x.x.x.js and jQuery.x.x.x-min.js

In terms of functionality, there is no difference between the jQuery-x.x.x.js and jQuery-x.x.x-min.js (also called minified version). However this can play a vital role in the performance of the web page.

How it affects the performance?
jQuery-1.4.4.js file size is 178 KB as against its minified version jQuery-1.4.4-min.js that is only 76.7 KB in size. So when your page loads in the client?s browser if you are not using minified version, it loads 178 KB file that takes more time to load than 76.7 KB.

Which version of jQuery file should be used?

In most of the recent releases so far, the core functionality of jQuery remains same however some more cool and better features are added. Ideally you should use the latest jQuery files available on the jQuery.com website. By doing this you ensure that your earlier functionality will still work and you can use new features available as part of the new release.

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
jQuery file can be loaded from Microsoft AJAX CDN. For more details, go to http://www.asp.net/ajaxlibrary/cdn.ashx. You will need to keep following tags in your page.

<script type="text/javascript" language="Javascript" 
src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js"></script>


Google - To load jQuery from Google Libraries API

jQuery file can be loaded from Google CDN for more details, go to http://code.google.com/apis/libraries/devguide.html. You will need to keep following tag in your page.
<script type="text/javascript" language="Javascript" 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>


Why to load jQuery file from CDN?

You may ask that if we can load the jQuery file from our own server why to load it from the CDNs. The answer is logical and very simple. The browser behavior is that whenever it loads any webpage, it keeps related files (eg. Javascript file, CSS file and Images) used for that page into its cache (also called history). When next time the user browses any web page, browser loads only those files that are new or modified and is not available in the browser cache or history. In this way, browser improves its performance and loads the page.

The possibility is that if more and more websites are using CDNs, the user might have already browsed some other web pages that is using CDNs jQuery file and that file may have into browser cache; so when user browse your page and you are also using CDNs file, the older cached version of jQuery file will be used. In this way your page will load faster as browser will not have to load the jQuery file for your page again.

The benefit
1. Faster page load as jQuery file need not to be downloaded
2. Saves your bandwidth as jQuery file is not loaded from your server
3. Scalable - generally CDNs place these files on the servers located at different geographical locations of the world so that they load faster so irrespective of from where your user is browsing your page, your application runs well.

No comments:

Post a Comment