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
  • 243
  • 4
  • 16

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
  • 5,937
  • 16
  • 43