1

I'm working on a very large coffeescript file another team originally developed. For some reason, there is an "undefined" at the end of pretty much every single block of code in the file. For instance:

  someFunction = () ->
    ajaxReq(
      blah blah
      undefined
    )
    undefined

 $("#some_id").click((e)->
    e.preventDefault()
    blah blah
    undefined
  )

   $(".some_class").change(->
     blah blah
     undefined
   )

Could someone please help me understand why they did this, and if it is necessary? Thank you.

Bryan Miller
  • 3,262
  • 4
  • 27
  • 51
  • 3
    [relevant](http://stackoverflow.com/questions/7391493/is-there-any-way-to-not-return-something-using-coffeescript) – Alec Nov 14 '16 at 22:10

1 Answers1

2

Because CoffeeScript returns the last expression from the function. In JavaScript, all functions return undefined by default. You don't have to write undefined in these cases since you aren't using the return value but if you were and wanted it to be consistent, you would have to return undefined.

Mike Cluck
  • 31,869
  • 13
  • 80
  • 91