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 Getting Started With ES2015 Create Functions Using Arrow Syntax Concise Arrow Function Syntax

JavaScript - Arrow Function Expression


So after watching this video, I can understand how a function declaration such as :

function divide1(a, b) { return a / b; }

Can be written as an arrow function expression:

const divide4 = (a, b) => a / b;

My question is, how do we call the arrow function expression.

For example, if i do something like divide4(8,2) i get an error. must i assign the divide(x,y) to a variable in order to use it?

Thanks for reading,

3 Answers

Stuart Wright
Stuart Wright
41,102 Points

I just opened a JavaScript console (in Chrome), and ran the following code:

const divide4 = (a, b) => a / b;
console.log(divide4(8, 2));

It correctly printed out 4. Maybe worth trying again to make sure? Your code seems correct to me.

Thanks, not sure what happened when I tried back then, but all seems to be well now :-)

Vasanth Baskaran
Vasanth Baskaran
4,333 Points

Derek, next time please specify the error too. So that we can narrow it down to what caused the issue to avoid it further.

Thanks, Happy Coding !!!

Kevin Ohlsson
Kevin Ohlsson
4,547 Points


I called the arrow function in workspace, it returned

treehouse:~/workspace$ d(6,3)
bash: syntax error near unexpected token `6,3'

It works on CodePen. https://codepen.io/ohlsson/pen/MBmNXV?editors=1111

Are workspaces updated to work with es6?