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

478Re: option.browser

Expand Messages
  • crlender
    May 4, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
      > I am curious, why is:
      > if (typeof foo === 'undefined') {
      > better than:
      > if (!foo) {

      In your example, if foo is not declared, it will result in a
      ReferenceError being thrown. This won't happen if you test with the
      typeof operator. I think DC's point was about avoiding the reference
      to 'window' when testing for a global variable, since 'window' is no
      longer part of option.browser.

      In addition to that, '!foo' converts a value to boolean, and some
      host objects (especially in IE) are known to throw exceptions if
      you try that. typeof is always safe*.

      - Conrad

      * Except, I think, in one weird Safari 2 bug when items of a
      NodeList are checked, but I'd have to look that up.
    • Show all 8 messages in this topic