I'm relatively new to ES6 Syntax. I had written a piece of code like follows:
const makeRange = (startTime, endTime) => {
return { startTime: startTime, endTime: endTime };
};
This worked fine, though I thought I shouldn't need the function braces ({ ...body ...}) for a one line return. The Following code:
const makeRange = (st, et) => { startTime: st, endTime: et };
As pointed by IntelliJ or Webstorm: "Expression Statement is not assignment or call".
How should I do it correctly(if it is valid)?
You can use ()
to wrap it like this:
const makeRange = (st, et) => ({ startTime: st, endTime: et });
console.log(makeRange(1, 2));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With