Why coffeescript use « return » statement everywhere?

coffeescript, javascript

Solution

CoffeeScript uses an implicit return if none is specified.

CS returns the value of the last statement in a function. This means the generated JS will have a `return` of the value of the last statement since JS requires an explicit `return`.

the return statement is for values (string, array, integer...)

Yes, and those values may be returned by calling a function, like `doSomething()` or `alert()` in your example. That the values are the result of executing a method is immaterial.

Problem

When writing something like that: ``` $(document).ready -> doSomething() doSomething = -> alert('Nothing to do') ``` is compiled into ``` $(document).ready(function() { return doSomething(); }); doSomething = function() { return alert('Nothing to do'); }; ``` In my understand, the return statement is for values (string, array, integer...) Why coffeescript do that ?

Original source