0

What is the difference between those two and when should I use each one of them?

Sometimes the script won't work unless I replace the $ with jQuery.

dominotrix
  • 367
  • 5
  • 19

1 Answers1

5

that's because $ is a shortcut for jQuery and many other frameworks, which means they can overwrite this variable

if you want to use it, a good practice is to do the following:

(function($){
    // here you can use $ and be sure it references jQuery
})(jQuery);

if you don't include any other frameworks on your website, then it makes no difference whether you use $ or jQuery

console.log(jQuery === $) // true
pwolaq
  • 6,343
  • 19
  • 45