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

JS Functions - Part 5 - Calling anonymous functions

I'm on the anonymous functions challenge and I don't understand the directions on the second part of the anonymous functions quiz. What are they looking for?

Can you post you code?

2 Answers

They're basically asking you to turn the already written function into something called an IIFE (Immediately-Invoked Function Expression).

You can't invoke an anonymous function later on unless you assign it to a variable. The only thing you can do with them is invoke them immediately, and you do that the same way you would with any other function — by adding () after it.

(function () {
  // code that does something
})(); // note the parentheses that invoke the function

Mod always reprimand me for give out answers

Thank you so much, that makes everything clear, I was overcomplicating things :)

I'm not sure what to write, I don't understand the directions, so I'm not sure what I'm being asked to do.

They want you to complete the self executing anonymous function. If you don't know what that is rewatch the video or google self executing function. Then compare what is there to what you see.