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 Convert to Arrow Function Expressions

Why does the console log undefined when running the third function?

const addToTen = num => 10 + num;

const divideUs = (num1, num2) => num1/num2;

const printMyName = (test) => console.log(test);

console.log(addToTen(5)); console.log(divideUs(10,5)); console.log(printMyName('Chad'));

Console:

treehouse:~/workspace$ node convert.js
15
2
Chad
undefined
treehouse:~/workspace$

2 Answers

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Hey friend Chadwick Savage , you have two mistakes here .
First , you have already defined console.log() statement within your printMyName function , and you are using it outside too. Second , you have used = operator in between function name and parenthesis , which should not be there

const printMyName(test) => console.log(test);

Just call the function with your desired name like this printMyName('Chad')
Hope it helps :)

Aakash is right there. I initially made the same mistake when copying my console.log statement. The printMyName function already logs to the console but returns nothing. So an extra undefined gets logged.

Thanks I was having the same problem.