Skip to main content

Arrow Functions

In our products, if we ask you to declare a function, we are expecting the Arrow Function syntax.

This function returns a string:

() => {
return "Hello World!";
}

Parameter names (if any) go inside the parentheses.

(a, b) => {
return a + b;
}

If the function has only one statement, and that statement returns a value, you can remove the brackets and the return keyword:

(a, b) => a + b;

You might see function parameter destructuring, explained further here.

// a function you might use for dynamic property
(context) => context.props.countryLabel + ": " + context.props.productLabel;

// can also be written as
({ props }) => props.countryLabel + ": " + props.productLabel;