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

Determine undefined

Expand Messages
  • Jing Ceawlin
    YAHOO.lang.isUndefined checks undefined using this code: isUndefined: function(o) { return typeof o === undefined ; } What I don t understand is, can t we
    Message 1 of 3 , Jan 31, 2008
    • 0 Attachment
      YAHOO.lang.isUndefined checks undefined using this code:
      isUndefined: function(o) {
              return typeof o === 'undefined';
          }


      What I don't understand is, can't we just do it like this:
      isUndefined : function(o) {
         return o === undefined;
      }

      I saw a lot of code examples using YUI's approach, but I can't think of anything which not equals to undefined but is actually undefined. Anyone knows the difference?
    • y_lsmith
      ... Jing, Most of the YAHOO.lang.is___ methods wrap simple operations. There are some that address more subtle nuances in the language. However, providing
      Message 2 of 3 , Jan 31, 2008
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "Jing Ceawlin" <zjply4000@...>
        wrote:
        >
        > What I don't understand is, can't we just do it like this:
        > isUndefined : function(o) {
        > return o === undefined;
        > }

        Jing,

        Most of the YAHOO.lang.is___ methods wrap simple operations. There
        are some that address more subtle nuances in the language. However,
        providing methods for common validations allows code authors to use a
        consistent syntax for ease of readability and maintainability.

        In the case of isUndefined, yes, you can verify val === undefined or
        typeof val === 'undefined'.

        Hope this helps,
        Luke
      • Jing Ceawlin
        Thanks. I just think val === undefined could be a little more efficient than typeof val === undefined .
        Message 3 of 3 , Jan 31, 2008
        • 0 Attachment
          Thanks. I just think val === undefined could be a little more efficient than typeof val === 'undefined'.

          On Jan 31, 2008 11:00 PM, y_lsmith <lsmith@...> wrote:

          --- In ydn-javascript@yahoogroups.com, "Jing Ceawlin" <zjply4000@...>


          wrote:
          >
          > What I don't understand is, can't we just do it like this:
          > isUndefined : function(o) {
          > return o === undefined;
          > }

          Jing,

          Most of the YAHOO.lang.is___ methods wrap simple operations. There
          are some that address more subtle nuances in the language. However,
          providing methods for common validations allows code authors to use a
          consistent syntax for ease of readability and maintainability.

          In the case of isUndefined, yes, you can verify val === undefined or
          typeof val === 'undefined'.

          Hope this helps,
          Luke


        Your message has been successfully submitted and would be delivered to recipients shortly.