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

How to add expection for "Use '===' to compare directly with undefined." error

Expand Messages
  • bartman1c
    How do I add the exception to this check both globally or in a single line of code, for example: if (typeof var === undefined ) { //many lines of code here
    Message 1 of 6 , Jul 25, 2012
    • 0 Attachment
      How do I add the exception to this "check" both globally or in a single line of code, for example:

      if (typeof var === 'undefined') {

      //many lines of code here

      }


      Thanks
    • douglascrockford
      ... if (var === undefined) { } You are welcome.
      Message 2 of 6 , Jul 25, 2012
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "bartman1c" <bartman1c@...> wrote:
        >
        > How do I add the exception to this "check" both globally or in a single line of code, for example:
        >
        > if (typeof var === 'undefined') {
        >
        > //many lines of code here
        >
        > }
        >
        >
        > Thanks


        if (var === undefined) { }

        You are welcome.
      • Jordan Harband
        Douglas - 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
        Message 3 of 6 , Jul 25, 2012
        • 0 Attachment
          Douglas -

          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.

          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.

          Thanks,
          - Jordan

          On Jul 25, 2012, at 10:58 AM, douglascrockford wrote:

          > --- In jslint_com@yahoogroups.com, "bartman1c" <bartman1c@...> wrote:
          > >
          > > How do I add the exception to this "check" both globally or in a single line of code, for example:
          > >
          > > if (typeof var === 'undefined') {
          > >
          > > //many lines of code here
          > >
          > > }
          > >
          > >
          > > Thanks
          >
          > if (var === undefined) { }
          >
          > You are welcome.
          >
          >



          [Non-text portions of this message have been removed]
        • 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 4 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 5 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 6 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.