What is the Cifrao ($) before a Function in JavaScript?

Posted on

Question :

Variants and functions, for example:

$(function() {})


Answer :

Usually related to jQuery . Otherwise they are only names for variables.

Javascript :
The variable name can start with letters, dollar sign ($) and underline (_). No numbers or other symbols are accepted. When the name of the variable is composed of more than one word it is not allowed to add space between them and it is usually used the CamelCase, where the first word begins with a lowercase initial and the next one with uppercase (variableName).
To create a variable in javascript just include the reserved word var on the front.

var texto;

Creating variables in this way is known as weak typing, where you do not have to define the nature of the information that will fill the variable. At any point in the code a variable that contained text may contain a number.

In jQuery :
All commands of jQuery have the alias $ (cifrão) as a shortcut. We can seamlessly mix% native% with JavaScript . The base of the jQuery are the Selectors, a selector defines in which part of the html or tag we are going to execute our code jQuery , the selectors of jQuery are identical to the CSS, for example, we have a div with a following structure, at first we can select this div of two forms in jQuery :

So jQuery or $("div") (Using alias $) or

So $("#divTeste") or jQuery("div") (Without using the alias $).


This is typical of jQuery. The $ is the alias of the jQuery library and this function is similar to window.onload , that is: it runs when the document has loaded.

Anyway, $ has no special meaning in JavaScript. It is a normal variable name, which is commonly used by jQuery.


Leave a Reply

Your email address will not be published. Required fields are marked *