0

So just something that I don't understand, and this could be a problem with my general javascript and es6 knowledge.

export const foo = (x,y) => { expression }

returns null

while export const foo = (x,y) => expression

returns the object I was looking for

apttap
  • 468
  • 2
  • 7
  • 17
  • The first one actually returns `undefined`. – 4castle Jan 18 '18 at 21:21
  • 3
    [Arrow Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) – luisenrike Jan 18 '18 at 21:21
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions - Information can all be found here. If you're using curly brackets, you must explicitly return a value. – Tom O. Jan 18 '18 at 21:22

1 Answers1

2

If you use the brackets you must use the word return to explicitly return something. Implicit return only works when there is a single statement and no brackets.

export const foo = (x,y) => { return expression }
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116