joep joep - 1 year ago 96
Javascript Question

Correct method to check jQuery has loaded

I have noticed a couple of methods to check whether jQuery has loaded, I'm curious to know if one is better than the other, or, more reliable?

In the past I have used this to check if jQuery exists:

window.jQuery


But, here is another option, which checks to see if the object is defined:

typeof jQuery !== 'undefined'


Alternatively, is there an even better method than one of these two?

Answer Source

I don't think voters understood what I was asking. Honestly don't understand why this was downvoted...

Both of my original suggestions do work, but, can't find any performance stats to suggest one or the other.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download