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 Concise Arrow Function Syntax

No argument function with a single line doesn't return the console.log() instead of calling it?

*I asked in the title

2 Answers

Steven Parker
Steven Parker
231,269 Points

To call a function, place parentheses after the function name, even if it doesn't require any parameters.

To access the function itself, use the name without the parentheses after it.

macfael
macfael
14,476 Points

I don't think so.

In this case, the function executes its code (the console.log statement) and then, when it's done, it returns undefined. This is because you didn't explicitly defined a return value for it.

For Example:

const sayHello = name => console.log(`Hello, ${name}`);

const returnValue = sayHello("John");
console.log(returnValue);

/* You will see in the console:

    >> Hello, John
    >> undefined 

*/