Nicholas Nicholas - 4 months ago 4
Javascript Question

Javascript : What is the difference between $(function () {}); and function () {}

What is the difference between

$(function () {
/* some functionality */
});


and

function () {
/* some functionality */
}


I've seen the first one used to initialize bootstraps tooltip (for eg.) but I tried the same with the second function it doesn't work. Can someone help me out please?

Answer

The first one, in jquery, is a shorthand for $(document).ready(function(){}).

Comments