0

in regards to: Checking if jquery is loaded using Javascript

alert(window.$?1:0)

is suggested in a comment on the original question

  • What is the interpretation of everything in this short line of code (what does it actually do?)

I believed that this would show alert "1" when jquery is loaded, but it actually shows alert "1" in a basic HTML page generated by d-o-c-Tab in vscode.

My initial belief was due to $ as a synonym for jquery in some cases however in most cases when jquery is not used others it seems to be a synonym for document.getElementByID

I do not have the reputation to comment on the original question yet.

GambitKSO
  • 41
  • 3
  • It's a [Ternary expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator); effectively an `if` condition condensed to a single line. Also It would be more reliable to use `window.jQuery` as that's less likely to be stolen than the `$` variable. – Rory McCrossan May 13 '20 at 13:22
  • What's your question? What's `?:` or what's `window.$`? – freedomn-m May 13 '20 at 13:30
  • Hi freedomn-m, the question is actually both inquiries, as you have described, simultaneously. The page linked by Rory explains "?:" quite well. As for "window.$" it seems just further practice/experience with javascript/browser standards on my side is necessary to know in just how many cases this identifier is used. – GambitKSO May 19 '20 at 07:32

0 Answers0