If I’m calling my JS scripts just before the closing body tag, is there a difference between using jQuery ready function like $(myfunc()); vs just using simply myfunc(); ?
If I’m calling my JS scripts just before the closing body tag, is there
Share
Only one difference would exist:
When you use
$(function(){...})(short for$(document).ready(function(){...}), you’re automatically wrapping the code in an anonymous function, thus creating a private scope. Variables defined usingvarinside this scope aren’t leaked to the global scope.Versus
When you don’t wrap the function call in a wrapper, both approaches have a similar result: