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!

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 Loops Working with 'for' Loops The Refactor Challenge – Duplicate Code

How are you calling value() as a function inside randomRGB(value) if it's not a function?

Inside function randomRGB(value), you define the variable const color as a template literal that interpolates the argument value, but you add a () thus making it look like a function.

How does this work?

1 Answer

Steven Parker
Steven Parker
224,872 Points

When randomRGB is called in the main program, the argument passed to it is randomValue, which is the name of a function. So for the duration of the randomRGB function, the parameter name "value" is equal to "randomValue", which means it can be called as a function.

When a function reference is passed as an argument to another function, this is often referred to as a "callback".