I’ve read an article about 20 top jQuery tips that uses the below code snippet:
//Use
$(function(){
//document ready
});
is better than using the below code:
//Instead of
$(document).ready(function() {
//document ready
});
I’ve always used the second code snippet. Is there any benefit on using the first one? Why is the second code snippet is better from performance perspective?
There shouldn’t signification difference in terms of performance. The first version is shorthand of second one which means if you use first version jQuery’s uses
readyhandler anyway.First version is short, quickly typed while second one is more readable.
The article that you mentioned is about tips which gives you a tip that there exists shorthand version of
readyhandler, it doesn’t bind you to always use first shorthand method, it is up to you which one you go with.