Home javascript symbol "$" in javascript

symbol “$” in javascript

Author

Date

Category

What value does the dollar symbol ($ ) in JavaScript? What is he answering and where is it appropriate to use?


Answer 1, Authority 100%

It can be used as a short and non-trivial name for a variable. This is done in many JavaScript frameworks. For example jQuery and Prototype.


Answer 2, Authority 127%

Nothing special, just this symbol can be used in identifiers, unlike many other languages. That is, ABC $ def – the legitimate name of the variable or function, for example.

You did not confuse JavaScript with the jQuery library? In it, $ is used under the global variable. Again, no magic, just the name of the variable.


Answer 3, Authority 55%

In JavaScript A $ sign is used to interpolation of expressions:

let data = [11, 22, 33];
Const str = `Number $ {Data [0]} from Data`;
Console.log (STR); // Number 11 FROM DATA

(only replace ‘on`)


Answer 4, Authority 45%

is a regular symbol.

var one $ two = true;
alert (one $ two);

Also also a dollar sign is used to access the main object JQuery if this library is connected.

or $ (id) in prototype means

document.getelementbyid (id)

Answer 5

& lt; form & gt;
User: & lt; input name = "username" type = "text" & gt; & lt; br & gt;
Email: & lt; Input name = "Email" Type = "Text" & gt;
& lt; / form & gt;
& lt; script & gt;
$ ('[Name = "UserName"] "). Val (app.user.username);
$ ('[Name = "Email"]'). Val (app.user.email);
& lt; / script & gt;

There is a joke in that it is not necessary to use

document.getelementsbyname ('username')
Document.getelementsByname ('Email')

And you can simply specify $ to access the JQuery main object (as mentioned above)


Answer 6

& lt; form & gt;
User: & lt; input name = "username" type = "text" & gt; & lt; br & gt;
Email: & lt; Input name = "Email" Type = "Text" & gt;
& lt; / form & gt;
& lt; script & gt;
$ ('[Name = "UserName"] "). Val (app.user.username);
$ ('[Name = "Email"]'). Val (app.user.email);
& lt; / script & gt;

Here you have a good example of using $!
I think everything became clear …

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions