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 jQuery Basics Introducing jQuery Blog Previewer: Getting Values from Form Fields

So what does the function do? We didn't define one

.

1 Answer

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Amandeep,

Almost the whole video is spent defining what that function does. In this case we are taking the method click() and instead of passing it some sort of static string or integer, we are passing it a whole function. This function is a callback function (if you want to search for the term to learn more about those). codeburst.io has a short & sweet blog post that explains why you'd want to use them in JavaScript.

If you look at the video at the 5:26 mark, you'll see the completed code. Everything from line 7 through 16 is the contents of that callback function. In this case, the function defined takes no parameters (hence the empty parentheses right after the word function), and then you see the opening curly brace that starts the function definition. The closing curly brace isn't until the beginning of line 17. When the user clicks the "Preview" button, it runs that code - taking what the user typed into the form and replicating it on the right hand side of the screen as a blog post preview.

I hope this helps clarify a bit - it definitely does take some getting used to!