Isn’t the undefined one incorrect? From what I know undefined means it can contain whatever value. So it could be no toilet paper, full toilet paper or anything in-between.
There’s deeper subtlety here. There are declared variables, uninitialised variables and variables that will at some point be declared, uninitialised or not, that don’t exist in the logic of the program flow yet. Compilers / interpreters may or may not make distinctions between these, especially if memory is (perhaps only considered to be) in short supply.
What specific languages do in these cases is wide and varied. Some automatically give all variables a safe, but identifiably undefined value the moment they’re declared, which may or may not be equivalent to the language’s interpretation of null. Or is equivalent in some senses but not others. Looking at you, Javascript.
In the toilet paper example, the holder might actually still exist but the middle bar might be missing for “identifiably undefined”, and the blank wall is that variable you have literally no idea about.
Maybe in trying to access it you amaze yourself by finding that you’ve punched through the wall and managed to grab some toilet paper from a neighbouring bathroom cubicle.
Maybe you instead discover your hand goes through a mincing machine and the pain, oh god why the pain nothing will ever be the same, is that my hard drive churning? No way to tell. Now that’s undefined behaviour.
Depends on what undefinedwe’re talking about. JavaScript undefined is just a value for undefined variables.
In C undefined behavior could be anything, ranging from reading in random garbage to time travel or summoning eldritch terrors.
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
Posts must be relevant to programming, programmers, or computer science.
No NSFW content.
Jokes must be in good taste. No hate speech, bigotry, etc.
Isn’t the undefined one incorrect? From what I know undefined means it can contain whatever value. So it could be no toilet paper, full toilet paper or anything in-between.
not undefined in mathematics, an undefined variable is just a variable that hasn’t been defined (yet) and is therefore nonexistent
There’s deeper subtlety here. There are declared variables, uninitialised variables and variables that will at some point be declared, uninitialised or not, that don’t exist in the logic of the program flow yet. Compilers / interpreters may or may not make distinctions between these, especially if memory is (perhaps only considered to be) in short supply.
What specific languages do in these cases is wide and varied. Some automatically give all variables a safe, but identifiably
undefined
value the moment they’re declared, which may or may not be equivalent to the language’s interpretation ofnull
. Or is equivalent in some senses but not others. Looking at you, Javascript.In the toilet paper example, the holder might actually still exist but the middle bar might be missing for “identifiably
undefined
”, and the blank wall is that variable you have literally no idea about.Maybe in trying to access it you amaze yourself by finding that you’ve punched through the wall and managed to grab some toilet paper from a neighbouring bathroom cubicle.
Maybe you instead discover your hand goes through a mincing machine and the pain, oh god why the pain nothing will ever be the same, is that my hard drive churning? No way to tell. Now that’s undefined behaviour.
Depends on what
undefined
we’re talking about. JavaScript undefined is just a value for undefined variables. In C undefined behavior could be anything, ranging from reading in random garbage to time travel or summoning eldritch terrors.This is JavaScript undefined specifically where it refers to a key that isn’t present.