If you want to check for the existence of the document object, you can use the following code: if (typeof document !== "undefined") { // document exists } else { // document does not exist } Once you can confirm that the document is available, you can then reference the document object without getting reference errors: Put the <script> element that loads the library before your code that uses it. OWNER: create and delete files 1 It had been working and I reverted everything to a state where it had previously been working and still it didn't work. Open a URL in a new tab (and not a new window), JavaScript check if variable exists (is defined/initialized). 4 The require() function is used when you need to load a package or a module into your JavaScript file. For example, given the example with jQuery above, we can make a call to noConflict () to restore the variable. Javascript answers related to "'define' is not defined" reference error $ is not defined jquery react '$' is not define errorMessage is not defined isempty is not defined Uncaught ReferenceError: function is not defined vue 'defineProps' is not defined no-undef angular is not defined In AngularJS Function is not defined - Uncaught ReferenceError Yes I was using this in the body section in the MVC style.