Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Callback Functions in JavaScript Callbacks with Timers Using Anonymous Functions with setInterval

Below is a way to not name a function variable, but is it a best practice?

setInterval(() => clockSection.textContent=getTime(), 1000);

Would it be longer than just using:


, so that's why you wouldn't use it?

1 Answer

Steven Parker
Steven Parker
215,939 Points

Sure, it's shorter, but it also saves you from repeating the same assignment code. That's in keeping with the best-practice "DRY" (Don't Repeat Yourself) principle.

Also, when an arrow function contains more than just an expression (as this one has an assignment), you should use the "long form" where you place braces around the function body. In this case, you could also place parentheses around the assignment to cause it to be interpreted as an expression, but that's rather esoteric and not nearly as clear.