Any difference between these two statements?
$(document).ready(function() {
// Code
});
$(function() {
// Code
});
JQuery is a JavaScript library. It would not have been invented had JavaScript was not there. jQuery is still dependent on JavaScript as it has to be converted to JavaScript for the browser in-built JavaScript engine to interpret and run it.
jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous for its philosophy of “Write less, do more”. Please refer to the jQuery Tutorial and jQuery Examples articles for further details.
It would not have been invented had JavaScript was not there. jQuery is still dependent on JavaScript as it has to be converted to JavaScript for the browser in-built JavaScript engine to interpret and run it.
JQuery is concise and one need not write much as scripting already exists. 6. Pure JavaScript can be faster for DOM selection/manipulation than jQuery as JavaScript is directly processed by the browser and it curtails the overhead which JQuery actually has. JQuery is also fast with modern browsers and modern computers.
In resolution, there is no difference, they are equivalent
From the relevant source code
jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
}
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
/* .... irrelevant code.... */
// HANDLE: $(function)
// Shortcut for document ready
else if ( jQuery.isFunction( selector ) )
return jQuery( document ).ready( selector );
}
}
If you mean
$(document).ready(function() {/* code here */});
and
$(function() {/* code here */});
then there is no difference between the two. The latter is just a shortcut that does the same thing as the former.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With