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

Re: indexOf in an If clause

Expand Messages
  • Douglas Crockford
    ... Yes, I think they should. ... No, I don t think so. The confusion with indexOf is that the not-found value is truthy, and only one of the found values is
    Message 1 of 7 , Apr 24 6:02 PM
      --- In jslint_com@yahoogroups.com, "Jordan" <ljharb@...> wrote:
      > `if (!a.indexOf('c'))` and `if (!!a.indexOf('c'))` both do not trigger the "weird condition" error.

      Yes, I think they should.

      > Is it worth also checking that Array.length is always used in an integer context and not a boolean one?

      No, I don't think so. The confusion with indexOf is that the not-found value is truthy, and only one of the found values is falsy. length does not have that confusion.
    Your message has been successfully submitted and would be delivered to recipients shortly.