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 trialDerek Vha
10,452 PointsJavaScript - Arrow Function Expression
Hi,
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
41,120 PointsI 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.
Vasanth Baskaran
4,333 PointsDerek, 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
4,559 PointsHello
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?
Derek Vha
10,452 PointsDerek Vha
10,452 PointsThanks, not sure what happened when I tried back then, but all seems to be well now :-)