Uncaught ReferenceError: $ is not defined

The issue:

In JavaScript the ReferenceError is very common. Many cases we get this ReferenceError. This ReferenceError clearly indicates that the program is trying to access something but the reference is not available.

When writing code using JavaScript this situation can happen for many cases. For example the code is calling a method and the function return will be an object. We have written further code using that object. If the function does not return anything then it will throw the reference error.

Another example would be jQuery $ is not defined. If we assume jQuery is loaded and if we write code using $ but the jQuery did not load properly then we will get this ReferenceError issue.

The solution

  • We will have to make sure the variables are available that are being used.
  • Make sure the library is properly loaded before we call anything from the JavaScript library
  • In case of ReferenceError $ not defined, make sure jQuery is properly loaded.