I was asked in an interview that how do you 'declare' jQuery? He did not mean a jQuery variable or a $(func())
. In case you find this question weird, please do not penalize me for this as I'm enquiring just cause I was asked. :)
I was asked in an interview that how do you 'declare' jQuery? He did not mean a jQuery variable or a $(func())
. In case you find this question weird, please do not penalize me for this as I'm enquiring just cause I was asked. :)
4 Answers
Reset to default 15You don't "declare" jQuery, you just include the file within a script tag:
<script src="/locationof/jQuery.js"></script>
If you look in the jQuery source it appends itself to window.$
and window.jQuery
when it runs as the source code is in a self-executing anonymous function.
(function( window, undefined ) {
// rest of source here
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
})(window);
We don't "declare" jQuery, we just add "reference" to the file where is this library in. For example:
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
That's it.
Perhaps he meant how to include it:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
I guess he was assuming that you say using a $
sign
<script>
tag to reference it? – Interrobang Commented Dec 21, 2011 at 7:10