During my coding journey, I encountered a situation where I was attempting to return an object from an arrow function. However, I noticed that the code snippet below was simply returning undefined
. After some investigation, I determined that the curly braces were being interpreted as marking the beginning and end of the function body. What baffled me was why a: 1
did not result in an error.
const foo = () => {a: 1};
foo();
// > undefined