Question: Does anyone know how to check if jquery has been loaded (with javascript) then load it if it hasnt been loaded.

something like

```
if(!jQuery) {
    //load jquery file
}

```

Answer: 
Method 1:

```
if (window.jQuery) {  
    // jQuery is loaded  
} else {
    // jQuery is not loaded
}

```

Method 2:

```
if (typeof jQuery == 'undefined') {  
    // jQuery is not loaded
} else {
    // jQuery is loaded
}

```

If jquery.js file is not loaded, we can force load it like so:

```
if (!window.jQuery) {
  var jq = document.createElement('script'); jq.type = 'text/javascript';
  // Path to jquery.js file, eg. Google hosted version
  jq.src = '/path-to-your/jquery.min.js';
  document.getElementsByTagName('head')[0].appendChild(jq);
}

```
```
var f = ()=>{
    if (!window.jQuery) {
        var e = document.createElement('script');
        e.src = "https://code.jquery.com/jquery-3.2.1.min.js";
        e.onload = function () {
            jQuery.noConflict();
            console.log('jQuery ' + jQuery.fn.jquery + ' injected.');
        };
        document.head.appendChild(e);
    } else {
        console.log('jQuery ' + jQuery.fn.jquery + '');
    }
};
f();

```