From what i understand, JavaScript requires variable to be defined using var keyword, and jQuery allows to define variables using $ symbol, I am wondering what added benefits does it bring when i define variable using jQuery, or is it purely preference? why will i use one convention over the other?
Also, what is the difference between the following variable declarations?
var foovar $oo$foo
varkeyword they will always be global, not matter where that initialization occurs. And the $ part does not “define” a variable in itself, it is just part of the variable name.$in variable names. It's hideous. I know it's somewhat of a convention for jQuery users but it's a terrible one. There's just no need. You should have sensible enough names that you don't need a$to know it's a jQuery object.