zngDuong
zngDuong

Reputation: 113

What does it mean $ and $$ in javascript?

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>');

Upvotes: 8

Views: 31750

Answers (8)

Jaromanda X
Jaromanda X

Reputation: 1

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.

Upvotes: 6

Jaydip Pansuriya
Jaydip Pansuriya

Reputation: 214

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

Upvotes: 0

juice
juice

Reputation: 587

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.

Upvotes: 3

KARASZI Istv&#225;n
KARASZI Istv&#225;n

Reputation: 31467

$ 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
);

Upvotes: 3

dashdashzako
dashdashzako

Reputation: 1346

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

Besides, the $ symbol is perfectly valid variable name.

Upvotes: 2

rapidoodle
rapidoodle

Reputation: 340

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

Read more here

Upvotes: 0

Ruslan Osmanov
Ruslan Osmanov

Reputation: 21492

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).

Upvotes: 8

rorschach
rorschach

Reputation: 2947

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

Upvotes: 0

Related Questions