How different var $firstName or and firstName in jQuery?

When I create var with jquery which is firstName value.

var $firstName = '';

or

var firstName = '';

How different '$' or not.

Answers 1

  • You can just use both of them as $ in variable name has nothing to do with jquery. As long as you have a valid javascript variable name, you can use $ before your variable name.

    So for example :

    var $firstName = "ABC";
    

    and

    var firstName = "ABC";
    

    when called in console.info() will output same things :

    console.info($firstName); // outputs "ABC" in firebug console.
    
    console.info(firstName); // outputs "ABC" in firebug console.
    

Related Articles