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

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

Expand Messages
  • douglascrockford
    ... I do not recommend selecting programming features based on insignificant performance findings. ... Such a mishaps has never been reported. It is fixed in
    Message 1 of 6 , Jul 25, 2012
    • 0 Attachment
      --- 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.
    • Marcel Duran
      How can I avoid ReferenceError for cases like: var bar = (foo !== undefined) && foo.bar; when var bar = (typeof foo !== undefined ) && foo.bar; works in this
      Message 2 of 6 , Jul 25, 2012
      • 0 Attachment
        How can I avoid ReferenceError for cases like:

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

        when

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

        works in this case.

        @marcelduran


        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]
      • Luke Page
        Be explicit about where foo is defined e.g. in the global scope var foo = foo; will not alter foo if it is already defined but will make sure the var is
        Message 3 of 6 , Jul 25, 2012
        • 0 Attachment
          Be explicit about where foo is defined e.g. in the global scope

          var foo = foo;

          will not alter foo if it is already defined but will make sure the var is
          present.

          or do window.foo === undefined.

          P.s. I think the warning is a great idea, shame so many people complain
          compared to those who are supportive.

          On 25 July 2012 20:13, Marcel Duran <marcelduran@...> wrote:

          > **
          >
          >
          > How can I avoid ReferenceError for cases like:
          >
          > var bar = (foo !== undefined) && foo.bar;
          >
          > when
          >
          > var bar = (typeof foo !== 'undefined') && foo.bar;
          >
          > works in this case.
          >
          > @marcelduran
          >
          > 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]
          >
          >
          >


          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.