Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) jQuery and AJAX The Office Status Project Revisited

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

$(document).ready(function() {}); vs $(function() {});

On the video, Dave uses

$(document).ready(function () {
  // Handler for .ready() called.
}); //end ready

However, when I was reading about .ready(), the documentation says the code above is equivalent to code below.

$(function() {
  // Handler for .ready() called.
}); //end ready

Does anyone know if there is a specific reason why we should use $(document).ready(function() {}); but not $(function() {});?

2 Answers

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

If anyone interested, there is a good explanation on W3 School's Invoking a Function as a Function part.

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

The question is why shorthand was not preferred? :)