0

I've summerized my problem in an example below, the problems is, if I use in an object an arrow function with only one item (23) in the function (as below), I've to not to use curly brackets for it to work. Why is so? I thought it was optional not to use curly brackets when in the function there is only one item. Thanks

  1. Doesn't work with curly brackets, returns undefined

    obj = { y: () =>  {23}  }
    console.log(obj.y());
    
  2. Works without curly brackets, returns 23

    obj = { x: () => 23 }
    console.log(obj.x());`
    

"to work with or without the curly brackets"

3limin4t0r
  • 19,353
  • 2
  • 31
  • 52
  • See also: [Arrow function expressions: Function body - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#function_body) – 3limin4t0r Jan 20 '23 at 15:58

0 Answers0