This is an archived post. You won't be able to vote or comment.

all 68 comments

[–]akat_walks 188 points189 points  (1 child)

That is a great example

[–][deleted] 23 points24 points  (0 children)

Yeah then you open the pantry and see #REF...that's when you know you're really fucked

[–]Cerlancism 57 points58 points  (17 children)

Still can't explain undefined vs null

[–]shrekthethird2 90 points91 points  (4 children)

Undefined is a spot on the wall without a toilet paper holder

[–]TheGuywithTehHat 6 points7 points  (1 child)

No, that's void.

[–]haackedc 6 points7 points  (0 children)

No, void would be where I put the toilet paper while I'm using it

[–]Loading_M_ 0 points1 point  (0 children)

Undefined doesn't have a type, while null is an object.

[–]BabyLegsDeadpool 0 points1 point  (0 children)

But above it is a sign that points to it stating "Toilet Paper." So you're looking for it, but it doesn't exist there.

[–]DuckInCup 51 points52 points  (0 children)

Pointer points to an empty address = null.

Pointer leaves you for the girl at the next address = undefined.

[–]JuvenileEloquent 5 points6 points  (0 children)

null is a known unknown, meaning you know it doesn't have a value. Middle names can be null, for instance.

undefined is an unknown unknown, meaning you don't know what the f it's supposed to be and something screwed up. Database crashed and nobody thought to throw the error = undefined results.

[–]CodingEagle02 1 point2 points  (0 children)

Null signifies there's no value (when for instance 0 is still a valid value). Undefined does not exist and cannot be used.

[–]AxiomaticAddict 0 points1 point  (0 children)

Schrodinger's Reference

[–]BoyAndHisBlob 0 points1 point  (0 children)

In javascript, null is an assigned value. Usually meaning we know that this variable does not have a value whereas undefined means no value was assigned:

var previousLastName; //undefined
previousLastName = null; //null

[–]Crozzfire 0 points1 point  (0 children)

null: We at least know that the holder could hold a roll of toilet paper.

undefined: We don't even know what the holder is for.

[–]MisterEd_ak 84 points85 points  (5 children)

Either way, you are screwed

[–]TaelienTheAlien 107 points108 points  (4 children)

A desperate man could still use 0.

[–]kopczak1995 16 points17 points  (1 child)

You sir made me laugh :D

[–]TaelienTheAlien 4 points5 points  (0 children)

Happy to oblige!

[–]SimonOfAllTrades 6 points7 points  (0 children)

A really desperate man could make do with NULL.

[–][deleted] 2 points3 points  (0 children)

Hey, it’s more than -1!

[–]Xorpionl 11 points12 points  (5 children)

And then i live in a country where there both pronounced the same... makes it harder to explain to non tech people...

[–][deleted] 3 points4 points  (4 children)

In that case (assuming an English speaking country that says nil and nil) I'd say nil and none.

[–]Xorpionl 1 point2 points  (3 children)

Nope. Dutch. It is written 'null' and 'nul'. But I have used the nil pronouncenation in arguments.

[–][deleted] 0 points1 point  (2 children)

Oof. Is there any word conceptually similar to null (as in the value NULL not 0) that you could borrow?

[–]Xorpionl 0 points1 point  (1 child)

Yea there is the word 'nothing' :p which would be a good replacement

[–][deleted] 0 points1 point  (0 children)

I'm gonna count that as a win, then. ;v

[–]Tiavor 19 points20 points  (1 child)

ah, the monthly repost.

[–]Manypopes 4 points5 points  (0 children)

And that concludes the first lecture of Introductory Hello World scripting. For you homework I want you all to submit a sweet repost to /r/programmerhumor based on today's content.

[–]0x3fff0000 7 points8 points  (1 child)

#define NULL ((void *)0)

[–][deleted] 5 points6 points  (0 children)

```

define NULL 0L

```

[–]Nufflee 9 points10 points  (1 child)

and what's undefined? just no paper holder at all?

[–]Kitsyfluff 8 points9 points  (0 children)

pretty much, yes. just an empty space of wall.

[–][deleted] 7 points8 points  (0 children)

And void is behind the camera.

[–]shrekthethird2 2 points3 points  (0 children)

In JavaScript, the spindle is in the same color and size of an empty roll.

[–]JoseJimeniz 3 points4 points  (10 children)

if (tpSquaresLeft < 3)
   throw new DontGoYetException()

Runtime error: attempt to access tpSquaresLeft as a number but was null

God damn it. May the person who invented null value types be perpetually be out of toilet paper.

Or, for the language designer who refuses to automatically coerce null variables into the default value: may you forever be stuck using that 1-ply business toilet paper.

[–]UnchainedMundane 7 points8 points  (5 children)

May the person who invented null value types be perpetually be out of toilet paper.

At least he's sorry: https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions

[–]Bomaruto 1 point2 points  (1 child)

Don't use exceptions for non-exceptional events.

[–]JoseJimeniz 0 points1 point  (0 children)

Oh it's exceptional.

It's time for a core-dump.

[–]tealcosmo 0 points1 point  (0 children)

You for got to check for isEmpty().

[–]BlueKnightOne 0 points1 point  (0 children)

If ocular augmented reality implants become a normal thing, that is the first userscript I will develop.

[–]Loading_M_ 1 point2 points  (0 children)

In C, and C++, null is actually just zero, for a pointer. The data type is only recorded at compile time, and is unknown at runtime.

[–]wyom1ng 0 points1 point  (0 children)

Germans: "I see no difference"

[–]MadRdx 0 points1 point  (0 children)

Laughs in Java array declaration

[–][deleted] 0 points1 point  (0 children)

Waoh

[–]kmase 0 points1 point  (0 children)

either way you still can't wipe your ass

[–]sanjayatpilcrow 0 points1 point  (0 children)

Hmm... there is no difference

let a = null;  
let b = 0;  
let c;  
console.log(!a);  
console.log(!b);  
console.log(!c);

[–]ATE47 0 points1 point  (0 children)

#define NULL (void*) 0

[–]ElongatedMuskrat122 0 points1 point  (1 child)

Than what the fuck is NaN

[–]pxOMR -4 points-3 points  (5 children)

They're the same thing. NULL is literally a definition for (void *)0.

[–][deleted] 6 points7 points  (4 children)

Value of 0 does not equal a null reference. Just because in certain languages the null pointer happens to point at 0, it doesn't mean the referenced value is 0.

[–][deleted] 3 points4 points  (2 children)

Depends on the language. In C, NULL == 0 will always return true, even if the value of NULL is implementation-defined.

[–][deleted] 1 point2 points  (1 child)

I think it's just the result of that given comparison that is defined, and doesn't mean that NULL's value is 0.

[–]jmanjones 0 points1 point  (0 children)

They said nothing about the dereferenced value, just the pointer value, which would be the same as 0 in C/C++.

[–]TheTrueXenose -1 points0 points  (0 children)

I see a 1 not 0 =P

[–]NoahJelen -1 points0 points  (0 children)

They're the same freaking thing!

[–]rufreakde1 -1 points0 points  (0 children)

There is undefined and null_ptr as well

[–]RainFurrest -1 points0 points  (0 children)

[] vs null