JavaScript Data Structures and Algorithms ES6 14

Hello, so on the Java Data Structures and Algorithims stage, on the 14th part of the ES6 course where you are supposed to “Use Destructuring Assignment to Pass an Object as a Function’s Parameters”. I was very confused on why these two lines produce different results.

const half = ({max, min}) => (max + min) / 2.0;
const half = ({max, min}) => { (max + min) / 2.0};

The top one is correct and lets me pass, but the other does not give out the same answer. Why is that?

When you use curly braces on the right side of an arrow function then you must explicitly return a value with a return statement. Since you are not then the function returns undefined.


So an inline function with the arrow notation that has parenthesis only doesn’t require a return statement, but a destructured assignment inline function requires a return statement?

Oh, ok. Thank you so much!

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