What is the difference between "variable $" and "variable" - JavaScript - jQuery

I initialized 2 variables, var1and $var2under $(document).ready(function()in jQuery. What is the main difference (or possible differences) between these two variables?

var1 = "var1";
$var2 = "var2";
$('#click1').click(function() {
    alert(var1);
});
$('#click2').click(function() {
    alert($var2);
});

Here is a working violin.

+5
source share
3 answers

There is no difference. Javascript allows you to use a character $in identifiers, such as variable and function names, in the same way that you can use letters, numbers, and some other punctuation characters. It does not really matter.

jQuery $ , , $, , jQuery. . $ , .

+13

. "$" , jQuery. . "var1", "$ var2" javascript jquery.

JavaScript, , "$" .

+1

I do not think there is a difference between the scope of two variables. It's just that $ var2 has the $$ sign in its variable name and contains a different string value.

I found this thread to explain the area of ​​JavaScript well.

0
source

All Articles