What's the difference between following types of var declaration in JavaScript?
$x
var x
var $x
$x and x are simply two different variable names. Like var x
and var y
. Simply using $x is an implied declaration, except that if $x exists in a higher scope, you'll use it. declaring var $x
sets up a new $x in the current scope which avoids conflicts with any other $x at a higher scope.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With