Need a Translation?

Mention the functionality which you can do with JavaScript

Given below are the things which you can do with JavaScript:
  1. Give response to a user instantaneously – Suppose a user has just submitted a comment form on your website. It would be a nice idea to show a thank you message to the user instantaneously using JavaScript. The server can also do this but it might take a little while for your thank you message to appear to the user, depending on how busy the server is.
  2. Make your web pages responsive to events – Since Web environments are dynamic, events happen all the time. With JavaScript, the web page can immediately react to these events the way you choose.
  3. Detect visitors browser – JavaScript can be used to detect a visitor's browser. You can choose to load a page specifically tailored to that kind of browser, depending on the browser and its capabilities.
  4. Creation of Cookies – JavaScript is quite efficient if you want to create cookies so that your visitors can enjoy a personalized experience the next time they visit your website.
  5. Validation of Web Form data – JavaScript can be used to validate web-form data before the form is submitted to a server. This saves the server from extra processing.
  6. There are tons of other functionality which can be implemented by JavaScript such as addition of cool animation effects to your web pages without using an external Flash plug-in, usage of the newest features of HTML5 such as canvas (to draw directly on your web page) and drag and drop capabilities, integrate your website with external web services such as Facebook, Twitter, etc.

Mention the functionality which you cannot do with JavaScript

Given below are the things which you cannot do with JavaScript:
  1. JavaScript cannot be forced onto a browser. Since JavaScript runs on client-side, the user has control over it. He can disable JavaScript on his browser or use older version of the browser in which case, JavaScript will not not work.
  2. Same Origin PolicyResources cannot be accessed or modified from another Internet domain with JavaScript, which is known as Same Origin Policy. The JavaScript script can only access resources on the same website.
  3. Server resources (such as databases) cannot be accessed with JavaScript. Since it is a client-side language, it's limited to what can be done on the client.

What are the various techniques to execute jQuery code?

There are two ways to execute the jQuery code:
  1. As and when the page loads:
    <script language="javascript" type="text/javascript">
$(function () {
$("#div1").css("border", "2px solid green");
});
</script>

OR

<script language="javascript" type="text/javascript">
$("#div1").css("border", "2px solid green");
</script>
Advantage: It doesn’t wait for the whole page to load completely, so in case you want the user to see the effects as soon as the corresponding elements are loaded, you can use this.

Disadvantage: If the element on which jQuery has to execute has not loaded yet, then it will throw an error (or you may not get the desired result). So, you will have to make sure that the element on which you want to work with jQuery is loaded first (you can place your jQuery code right after your HTML element).
  1. After the complete page has loaded: You can wrap your code in .ready function to execute jQuery only when the complete DOM objects (the complete page has been loaded) has loaded.
    <script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#div1").css("border", "2px solid green");
});
</script>
    This is a better and safer way to execute jQuery. This makes sure that jQuery code will execute only if complete page has been loaded in the browser. This eliminates the possibility of any undesired behavior on the page.

What is CDN?

CDN is an acronym for Content Distribution Network or also called Content Delivery Network. It 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 accesses 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 host jQuery files:

a) Microsoft – A jQuery file can be loaded from Microsoft AJAX CDN using the 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>
b) Google – A jQuery file can be loaded from Google CDN using the 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> 
Benefits of loading jQuery file from CDN:
  1. The page loads faster as the jQuery file need not be downloaded when the web page is requested.
  2. Since the jQuery file is not loaded from your server, it saves the bandwidth.
  3. Scalability - the CDNs generally place the jQuery file on the servers located at different geographical locations so that they load faster. So irrespective of where your user is browsing your page, your application runs well.
How to load jQuery file in case CDN in not available:
It may happen that the CDN (which you have used) in unavailable. This is the case when you should load your local jQuery file that is available on your server so that all jQuery related functionality still works fine on the web page. Given below is the code to do so:

<!-- START - jQuery Reference -->
<script type="text/javascript" language="Javascript" 
        src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js"></script>
    <script type='text/javascript'>//<![CDATA[
        if (typeof jQuery == 'undefined') {
            document.write(unescape("%3Cscript 
        src='/Script/jquery-1.4.1.min.js' type='text/javascript' %3E%3C/script%3E"));
}//]]>
</script>
<!-- END - jQuery Reference -->

Replace the above highlighted path with your own jQuery file path on the server.

How can a developer use jQuery?

jQuery can be download from jquery.com. After downloading the jQuery file, include it in the web page using the following mark-up under the <head></head> tag:

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

What is jQuery?

jQuery is a well written JavaScript code. As quoted on official jQuery website, "it is a fast and concise JavaScript Library that simplifies traversal and manipulation of HTML document, event handling, animation, and Ajax interactions with an easy-to-use API that works across a multitude of browsers for rapid web development".

It is a free and open source software. Microsoft has integrated jQuery officially into its IDE Visual Studio 2010 (jQuery intellisense is available in Visual Studio 2010).

jQuery is very compact and well written JavaScript code that increases the productivity of the developer.
  • It helps to develop browser compatible web page and improve the performance of an application.
  • It is fast and concise and helps to implement UI related critical functionality without writing hundreds of lines of codes.
  • It is extensible – jQuery can be extended to implement customized behavior.
  • No need to learn fresh new syntax to use jQuery, knowing simple JavaScript syntax is enough.