Arrow functions and return values

Jussi Kalliokoski jussi.kalliokoski at gmail.com
Thu Nov 29 00:41:41 PST 2012


It's a bit unclear to me how arrow functions react to semicolons, for
example:

var a = (c) => {
  var b = 2;
  b * c;
}

a(4);

To me, it seems like this should return undefined. After all, the last
statement in the function is empty. To actually return b * c, you should
drop the semicolon:

var a = (c) => {
  var b = 2;
  b * c
}

a(4);

This would be consistent with, for example, Rust and would help avoid
annoying accidental returns (see [1] for discussion about this wrt
CoffeeScript).

Cheers,
Jussi

[1] https://github.com/jashkenas/coffee-script/issues/2477
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121129/d9f8be72/attachment.html>


More information about the es-discuss mailing list