What is the difference between
$(function() {
// bind some event listeners
});
and
$(function() {
// bind some event listeners
}());
$(function() {
// bind some event listeners
});
In above case the function is passed to the jquery which will get executed once document is ready.
$(function() {
// bind some event listeners
}());
In above case the return of the function is passed to the jquery. Since the function is se3lf executing itself, it will get executed immediately and whatever the function returns will get passed to the jquery, so this is not a good way because the objective is to execute the function once document gets ready which is not happening in this case
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