Loading ...
Sorry, an error occurred while loading the content.

Re: Function return with and without value does not give any warning

Expand Messages
  • Douglas Crockford
    ... C s interest in producing an error here is due to its type system. It want to generate different code for void functions than for other types of functions.
    Message 1 of 7 , Mar 8, 2010
    View Source
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Woomla" <woomla@...> wrote:
      >
      > The code snippet below doesn't give any errors or warnings. But return with and without a value is used. Shouldn't that at least issue a warning?
      >
      >
      > "use strict";
      >
      > function test(a, b)
      > {
      > if (a)
      > {
      > return true;
      > }
      > if (b)
      > {
      > return;
      > }
      > }
      >

      C's interest in producing an error here is due to its type system. It want to generate different code for void functions than for other types of functions. JavaScript does not have this difficulty. There are no void functions. Every function returns a value, even if it is only the undefined value.

      I am reluctant to add more complaints to JSLint unless there is some evidence that doing so will make programs better. I don't see the benefit to the warning you are demanding. Can you offer some evidence?
    Your message has been successfully submitted and would be delivered to recipients shortly.