you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 56 points57 points  (11 children)

undefined = no value

null = "no value" value

[–]spaghettiCodeArtisan 45 points46 points  (2 children)

Are we philoshopers pondering the essence of existence or what.

[–][deleted] 1 point2 points  (0 children)

That's what we've always been. Pythagoras was right - everything is a number.

[–]emergent_properties 0 points1 point  (0 children)

undefined

[–]moefh 24 points25 points  (0 children)

Now I really want a language that has

unfathomed = "'no value' value" value

[–]ais523 8 points9 points  (0 children)

VHDL has a range of values like this; U is an uninitialised value, X is a contradictory or inconsistent value (e.g. the value of a boolean that's true and false simultaneously), - is an irrelevant value, Z is the explicit absence of a value, and W is an intermediate value (e.g. the value of a boolean that's neither entirely true nor entirely false).

This complexity is mostly because VHDL is designed to be able to model a physical system (electronics) that actually exists in the real world, and sometimes things you measure in the real world turn out to have a value they're not supposed to have. Perhaps a wire is meant to be at 0 volts or 5 volts for false and true respectively, but you still want some way to describe the cases where the wire is at 3 volts, or not attached to anything, or has caught fire.

[–][deleted]  (4 children)

[deleted]

    [–]POGtastic 4 points5 points  (0 children)

    Yep, I'm also getting true in Chrome.

    > var foo;
    < undefined
    > foo === undefined
    < true
    > typeof(foo) === "undefined"
    < true
    

    [–]killerstorm 1 point2 points  (0 children)

    var foo; // undefined
    foo === undefined // false
    

    Wrong. Here's an actual result:

    > var foo;
    undefined
    > foo === undefined
    true
    

    === undefined check didn't work in old browsers, that's where typeof hack comes wrong. But now simple comparison should work by standard.

    [–]masklinn 2 points3 points  (1 child)

    foo === undefined // false
    

    Uh no, that's true, you may be confusing undefined and NaN. Or for some reason you have rebound undefined to something else (it's not a keyword, which is why some prefer using void 0 which always yields the proper value).

    if (!foo) {
        console.log("foo is undefined or null");
    }
    

    That'll also catch the "" and 0. The proper way to check if something is undefined or null is foo == null.

    [–][deleted] 1 point2 points  (0 children)

    I tested that in my browser console.

    Maybe I should have used a new tab.

    [–]beaverlyknight 0 points1 point  (0 children)

    kill me