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 JavaScript Foundations Functions Anonymous Functions

Nazaam Kutisha
Nazaam Kutisha
7,667 Points

Help with this challenge

Set the variable 'anonymousFunction' to be an anonymous function without any code to be executed.

my response isn't working here.

<script>
      var anonymousFunction = function(); {

      anonymousFunction();
      };

   </script>

4 Answers

Thanks Dave, I should add the semicolon at the end of the function curl braces. The semicolon I was talking about was after the anonymous function like so:

var anonymousFunction = function();  {

At least when I tried to run the code this way I received a syntax error, but maybe I had another error in the code the created that issue. I was trying to recreate the problem in my environment, so I could help answer the question.

Dave McFarland
Dave McFarland
Treehouse Teacher

Yeah, definitely. That IS a syntax error.

I do not believe you have to call the function inside of itself. Also, after the function() you have a semi-colon which will lead to a syntax error. If you delete the function call inside the curly braces and the semi-colon it should work. For example:

var anonymousFunction = function() {

}

This should work because now the variable is set to that anonymous function, and that function now does nothing.

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi Matthew,

Excellent answer. You should add a semicolon at the end of the statement:

var anonymousFunction = function () {

};

You won't get a syntax error without the semicolon, but it's technically correct. Because you are assigning a value to a variable you're creating a JavaScript statement and it should end with a semicolon, just like any JS statement:

var a = "apple";
Nazaam Kutisha
Nazaam Kutisha
7,667 Points

This worked for the challenge

var anonymousFunction = function() { };

Great Responses..

I am glad we could help Nazaam!