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 and the DOM (Retiring) Responding to User Interaction Functions as Parameters

How would you do this same example of passing a function into another function using arrow functions instead?

I don't get it, Guil was using arrow functions earlier in this track, but for this example he uses the old style of declaring function, so, its confusing me. I don't know how to use this same example in the video using arrow functions instead.

function say(something){
    console.log(something);
}

function exec(func, arg){
    func(arg);
}

exec(say, "hi, there");
Julian French
Julian French
3,257 Points

Hey, would you mind pasting in the example code here? Thanks!

Let me know if this helps

const say  = something => {
    console.log(something);
}

const exec = (func, arg) => {
    func(arg);
}

exec(say, "hi, there");

1 Answer

Hello, there.

I know this is a old question, buy maybe you can still use this answer, or other students in the Community.

const exec = (func, arg) => func(arg); exec(something => console.log(something), 'Hi there')

That would work