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

2945Re: [jslint] Re: How to add expection for "Use '===' to compare directly with undefined." error

Expand Messages
  • Marcel Duran
    Jul 25, 2012
      How can I avoid ReferenceError for cases like:

      var bar = (foo !== undefined) && foo.bar;


      var bar = (typeof foo !== 'undefined') && foo.bar;

      works in this case.


      On Wed, Jul 25, 2012 at 11:47 AM, douglascrockford <douglas@...>wrote:

      > **
      > --- In jslint_com@yahoogroups.com, Jordan Harband <ljharb@...> wrote:
      > > I found http://jsperf.com/typeof-vs-undefined-check/3 awhile back which
      > shows that `typeof foo === "undefined"` is faster in some browsers and
      > slower in others.
      > I do not recommend selecting programming features based on insignificant
      > performance findings.
      > > Given that "undefined" can be redefined in older browsers, what reasons
      > remain for warning on checking undefined with typeof? The only other thing
      > you've implied is that people don't redefine undefined. Obviously you may
      > pick whichever defaults you like. Since it's possible to redefined
      > undefined, however, would you please add a "tolerate" option for this? It
      > would be appreciated.
      > Such a mishaps has never been reported. It is fixed in ES5. JSLint does
      > not allow it.

      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic