Arrow function in javascript

Just thinking out loud. Does anyone has the idea:

When using function with parameter in it… just like this

const kode = (light) =>{ return anything};

then converted to arrow function like this…

const kode = light => anything;

My question? What happen to converting function without parameter?

const kode = () =>{ return anything};

Hope i’m clear enough?

Those are all arrow functions

Parentheses around the parameters are optional when there’s one parameter, since that isn’t the number of parameters you’ve got, they’re not optional

Thanks ionatan… I think i need to rephrase my question.

I mean what happen to converting this…
const kode = () =>{ return anything};
to something like this…
const kode = light => anything;

Those have different parameter lists

An empty parameter list is a set of empty parenthesis

The body can either be a single expression or curly braces with statements in it. Which one of those you use doesn’t affect how you write the parameter list. It makes no difference which you use so for the purpose of asking this you should pick the same one for “both cases”, except there aren’t two such cases

The things you’re changing are independent of each other. They’re all arrow functions, you’re not converting between two kinds

You might wanna have a look at msdn’s page for arrow functions, reading a relatively complete and correct description may be better than playing whack-a-mole with your understanding
(and you may generally want to refer to msdn for finding out how things are written or behave or otherwise, in javascript)

I think what you’re asking is what would an arrow function with no parameters and no explicit return statement look like.

const kode = () => { return anything }
can be rewritten as:
const kode = () => anything

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.