What is JQuery $ sign symbol & How to Declare JQuery Variable Object Variable

What is Variable:
In a programming Language, 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 is the information which is used when program is running. The data consists of variable values and constants or fixed values, that never change. In this article i will explain how one can declare JQuery Variable as well as JQuery Object type variable. Also i will explain what is Jquery $ sign.

Declaring a variable in JQuery:
Declarinag a variable in JQuery almost like javascript declaration. See an example from below:

<script language="javascript">
            $(document).ready(function() {          
            var a=10;
            var b=20;
            var c=a+b;
            alert(c);
            });
    </script> 

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;
            alert($c);
            });
    </script>

JQuery Object Declaration Syntax:
JavaScript supports Object concept very well. We can declare object variable in JQuery 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
            
            alert(Developer.$Name)
            
            // Write or set properties
            Developer.$Name="Bikash"
            alert(Developer.$Name)            
        });
    </script> 

Hope now you can use JQuery in a Object Oriented Way.

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code