7
votes

Please explain the meaning of the $ and $$

This is sample code use $ and $$: https://github.com/cytoscape/cytoscape.js-qtip/blob/master/cytoscape-qtip.js

what mean this code use $:

var $qtipContainer = $('<div></div>');
8
I don't think there is any meaninguser6360214
Both $ and $$ are valid names for variables, they have no special meaning.Madara's Ghost
Just aliases to the 2 global variables you can see passed at the end of the file (jQuery and cytoscape)George Kagan

8 Answers

8
votes

The whole code is just a function call with two arguments:

;(function( $, $$ ){ 'use strict';
  // skipped
})(
  typeof jQuery !== 'undefined' ? jQuery : null,
  typeof cytoscape !== 'undefined' ? cytoscape : null
);

The first argument is jQuery global variable (or null, if jQuery is undefined), and the second is cytoscape global variable (or null, if is undefined).

6
votes

In the browser developer tools console - at least in Firefox, IE11, (can't test lesser IE's), Edge and Chrome - $ and $$ do have particular functions (if the page hasn't defined those vars) - see MDN Documentation for helper commands in the Web Console Helpers.

3
votes

$ and $$ are valid variable names in JavaScript, they have no special meaning.

Usually they set their value to library instances, in your example if you check the closure call, at the end of the file you'll see that $ is jQuery in this case if it is defined and $$ is cytoscape.

See the corresponding code part:

;(function( $, $$ ){ 'use strict';
  // ...
})(
  typeof jQuery !== 'undefined' ? jQuery : null,
  typeof cytoscape !== 'undefined' ? cytoscape : null
);
3
votes

It's a naming convention in JavaScript for variables that store JavaScript objects. Their name should start with $. Exactly like in your example:

var $qtipContainer = $('<div></div>');

Because JavaScript is untyped language, this is useful way for programmers to distinguish whether variable stores jQuery object or for example DOM object.

2
votes

Referring to the source code, $ is jQuery, and $$ is cytoscape.

Besides, the $ symbol is perfectly valid variable name.

0
votes

It's jQuery, a JS framework for DOM-manipulation and all sorts of other fun stuff.

0
votes

$ sign is a valid identifier in JavaScript. $$ was a notation that used back when packer was popular but no significance now.

Read more here

0
votes

If you are using prototype javascript then $$() & $() are selectors. For more information visit https://www.tutorialspoint.com/prototype/prototype_utility_methods.htm