0

What means and what will do this piece of code?

(function ($) {}(jQuery));
  1. What is relation between "$" and "jQuery".
  2. Do brackets "(", ")" on edges of code has any function? Do they do something?
krzyhub
  • 5,019
  • 10
  • 35
  • 63

2 Answers2

2
(function ($) {}(jQuery));

jQuery is existing jQuery object , $ is same jQuery object within Immediately-Invoked Function Expression (IIFE) statement {}

Do brackets "(", ")" on edges of code has any function? Do they do something?

Yes. Comma , separates arguments to function

e.g.,

(function($, $$) {
  // `$`:`{"abc":123}` ; `$$`:`{"def":456}`
  console.log($["abc"], $$["def"]) // `123` , `456`
 // set `$` within IIFE to object `{"abc":123}` ,
 // set `$$` to object `{"def":456}`
}({"abc":123}, {"def":456})); 
guest271314
  • 1
  • 10
  • 82
  • 156
1

What is relation between "$" and "jQuery"?

$ is shorthand for jQuery. Sometimes $ is disabled as it may conflict with other Javascript libraries you are using. It is otherwise identical.

and refer this

http://api.jquery.com/jQuery.noConflict/

Balaji Marimuthu
  • 1,742
  • 9
  • 13