What's the difference between following types of var declaration in JavaScript?
$x
var x
var $x
No difference except for scope. $x is just a variable name like x. var creates variables in a local scope, otherwise they are global.
This has nothing to do with jQuery, really.
$x and x variable names are no more different than xy and x. However, $ is sometimes used at the beginning of variable names by convention to indicate that the variable stores a reference to a jQuery object.Nothing. I find it good practice, however, to precede variable names with a $ if it returns a jQuery object and without if it returns a DOM object or other type (string, etc.)
The term 'var' is useful for determining scope. Always use 'var' on first declaration, or on anytime you need a variable to be local in scope.