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

2927Re: [jslint] Re: typeof null

Expand Messages
  • Michael
    Jul 19 9:29 AM
    • 0 Attachment
      JSLint will complain if you try to redefine undefined:
      Read only.


      undefined = "foo";




      On Thu, Jul 19, 2012 at 12:26 PM, [MACSkeptic] Mozair Alves do Carmo JĂșnior
      <macskeptic@...> wrote:

      > If you are concerned that undefined might be redefined, you can always wrap
      > your code with a self invoking function, right?
      >
      > Something like:
      >
      > (function (undefined) {
      >
      > } ());
      >
      > On Thu, Jul 19, 2012 at 1:10 PM, spence.randall@... <
      > randall@...> wrote:
      >
      > > **
      > >
      > >
      > >
      > >
      > > I foresee a minor problem with this: in most browsers, undefined is not
      > > read-only and can be overwritten, which means if you have other code on a
      > > page outside of your control, it's safer to do a typeof === 'undefined'
      > > check rather than x === undefined.
      > >
      > > For example:
      > >
      > > var undefined = 1,
      > > x;
      > > alert(x === undefined);
      > >
      > > Will alert false, whereas
      > >
      > > var undefined = 1,
      > > x;
      > > alert(typeof x === undefined);
      > >
      > > will alert true, as expected.
      > >
      > > Note, only Firefox seems to throw an error saying undefined is read-only.
      > >
      > > Granted it is irresponsible and insanely stupid to redefine undefined,
      > but
      > > their are some irresponsible and insanely stupid people out in the wild
      > > writing code, the later test at least seems more bullet proof.
      > >
      > > Thanks,
      > > Randall
      > >
      > >
      > > --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...>
      > wrote:
      > > >
      > > > JSLint will now warn if you write
      > > >
      > > > typeof x === 'null' || typeof x === 'undefined'
      > > >
      > > > instead of
      > > >
      > > > x === null || x === undefined
      > > >
      > >
      > >
      > >
      >
      >
      > [Non-text portions of this message have been removed]
      >
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      >


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