Monday, May 10, 2010

How to declare JQuery variable & What is JQuery $ sign symbol

Please visit my new Web Site

In my first article i have discussed on how to start JQuery in your application. Here in this article i will explain how one can declare simple JQuery variable as well as object type Jquery variable also i will explain what does it mean by Jquery $ sign.

At first What is variable:
In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Typically, a program consists of instructions that tell the computer what to do and data that the program uses when it is running. The data consists of constants or fixed values that never change and variable values (which are usually initialized to "0" or some default value because the actual values will be supplied by a program's user).

Now declaring a variable in JQuery:
Declarinag a variable in JQuery almost like javascript declaration. See the below example which will use simple variables:
<script language="javascript">
            $(document).ready(function() {          
            var a=10;
            var b=20;
            var c=a+b;

Now what is Jquery $ sign:
To initialize an object JQuery uses $ symbol. You can use this symbol to pass selector, function, string etc to execute or implement some functionality. You can replace the symbol $ by jquery word which will give you same result. Basically its a notation you have to use to pass a selector.

So the best way of declaring a variable in JQuery based on my first example is:
<script language="javascript">
            $(document).ready(function() {          
            var $a=10;
            var $b=20;
            var $c=$a+$b;

Object Declaration:
JavaScript supports Object concept very well. We can declare object variable same as javascript. You can create an object using the object literal in JQuery as follows:
<script language="javascript">
        $(document).ready(function() {          
            var Developer = {
               $Name: "Shawpnendu",
               $Experience: 6
            //You can write and read properties of an object using the dot notation as follows:
            // Read Properties
            // Write or set properties

Hope this will help you.


Want to say something?

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash