Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 967287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:17:29+00:00 2026-05-16T02:17:29+00:00

See http://jsfiddle.net/FDhQF/1/ for a trivial example. What’s the difference between something being undefined and

  • 0

See http://jsfiddle.net/FDhQF/1/ for a trivial example.

What’s the difference between something being undefined and something not being defined in Javascript? For instance, trying to access a property for an object (effectively, trying to access a variable) that isn’t defined will return undefined. But you can also set something = undefined. When you do that, trying to access it still return undefined, but the pointer is still there. An example, as above, is how iterating over an object still goes over the property that you’ve (re)declared as undefined. It seems like there are two different sorts of undefined. Can anyone shed some light on the situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:17:29+00:00Added an answer on May 16, 2026 at 2:17 am

    Both, accessing a property that isn’t defined on an object and a property that contains the primitive undefined value, will return you undefined.

    For example:

    var obj = {
      a: undefined
    };
    
    obj.a; // undefined
    obj.b; // undefined
    

    The difference is that a is an own property, and b isn’t:

    obj.hasOwnProperty('a'); // true
    obj.hasOwnProperty('b'); // false
    

    In the first case a is an own property, even if it contains undefined as its value. In the second case, b is not an own property, accessing obj.b will look for a property named b, all way up in the prototype chain.

    When the prototype chain ends (when it reaches an object with a null [[Prototype]]), the property lookup ends and undefined is explicitly returned.

    You should know that the hasOwnProperty method checks only if the property physically exist on the object (own properties), but we have also inherited properties, for that case we can use the in operator, for example:

    function Test () {}
    Test.prototype.a = 'foo'; // instances of Test will inherit from Test.prototype
    
    var obj = new Test(); // { a="foo",  b="bar"}
    obj.b = 'bar';
    
    obj.hasOwnProperty('a');  // false
    'a' in obj;               // true
    obj.a;                    // 'foo'
    
    obj.hasOwnProperty('b');  // true
    

    As you can see, obj inherits from Test.prototype, and the a property is not an own property, but it is available through the prototype chain. That’s why hasOwnProperty returns false and the in operator returns true.

    You can see how internally properties are resolved by the [[Get]] internal operation

    Notes:

    • Accessing undefined as an identifier is not considered to be safe on ECMAScript 3 (the most widely implemented version of the language standard), because instead of being a language keyword (such as null for example) is just a property of the global object, and it is writable on this version of the Spec., meaning that if someone replaces its value (e.g. window.undefined = 'LOL';) , it will break your code.

    The typeof operator as @strager mentions can be used instead, for example:

    if (typeof obj.prop == 'undefined') { /*....*/ }
    

    This operator returns always a string (it’s safe to use == :), and its value depends of the type of its operand, the possible values are described here.

    Another common way to solve this is to declare your own undefined variable, available on the scope of your functions, for example, some libraries use the following pattern:

    (function(undefined) {
      // code here
    })();
    

    The function has an argument named undefined, and it is executed immediately without passing any value to it (the last pair or parens make the invocation).

    Maybe is worth mentioning that the undefined global property was finally described on ECMAScript 5 as non-writable (immutable, as well non-enumerable and non-configurable -non deletable-).

    • Using the hasOwnProperty method directly from an object instance is also not considered as safe, because if some object has a property with the same name, the original method will be shadowed. For example:

      var obj = { hasOwnProperty: function () { /* evil code :) */ } };
      

    If you call:

        obj.hasOwnProperty('prop'); 
    

    The method defined on the object will be executed (and you wouldn’t want this since you know exactly which method you want to invoke…), because it shadows the one from the Object.prototype, however it can be safely invoked by:

        Object.prototype.hasOwnProperty.call(obj, 'prop');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

to see the error: http://jsfiddle.net/sEdGz/2/ //the script works, but the clicked radio isn't checked=checked
in this example http://layout.jquery-dev.net/demos/toggle_alternate_layouts.html you can see that the resize is on the fly.
I’m trying to prevent the browser from using the :hover effect of the CSS,
Okay to get started I am using Jquery-Flot to plot a radial graph I
I am trying to create a timeline. There is a dragger element and some
I have a form which has expanded beyond the desired height in IE6 only
I am making a greasemonkey script and i would like a link to go
How do I access values set by $.data() inside a function or object $('#timers').data('firsttimer',
I have a simple jQuery function: $('#selectable1 span').live('mousedown', function() { var ff = $(this).css(font-family);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.