+ 5

Variable syntax - Jquery

I was seeing jquery codes. Then I realized that in the syntax of variables I had a $ in the word type: var $obj; I thought I had a mistake. I tried to use it and it worked, but how could it have worked out if special characters are invalid in creating the variable name? Is this an exclusive property of jQuery? What is the difference between a normal name and a with $?

9th Jan 2018, 2:11 PM
David Wesley
David Wesley - avatar
5 Respuestas
+ 2
Go to the sololearn lesson about naming variables in JavaScript. It says that a variable name must start with a letter, underscore or dollar sign. There's nothing special with variables that have a dollar sign in their names. For example, the jQuery $ it's just a regular function.
29th Jan 2018, 11:11 PM
Luis Lopes
Luis Lopes - avatar
+ 7
You probably misunderstood the syntax of jquery.. https://www.w3schools.com/jquery/jquery_syntax.asp
9th Jan 2018, 3:04 PM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 6
@Luis Lopes valeu man... Agora tudo faz sentido...
30th Jan 2018, 1:09 AM
David Wesley
David Wesley - avatar
+ 4
@Md. Nafis UI Haque Shifat It's about the name of the variables that could have the $ sign. Example: var $var1 = 123; var $var2 = 123; var $var3 = 123; The above example works in jQuery, even though it contains the $ sign. Why is this valid?
9th Jan 2018, 3:59 PM
David Wesley
David Wesley - avatar
+ 2
@David De nada, eu também pensava que era algo especial
30th Jan 2018, 11:51 AM
Luis Lopes
Luis Lopes - avatar