Depending on what declaration statement is used to declare a variable, it can be confined to different parts of the code, unable to be used elsewhere. This is called scope, and it affects where a variable is valid in a program.
In the first example,
someVariableName is, you guessed it, the name of the variable, and
a value is the value of that variable. So if we were to use
someVariableName somewhere in our code after declaring it (and it fell within a valid scope of use), the code would know we mean
a value when we use that variable again.
Undefined data types are those that don’t have anything assigned to them yet. Imagine you’ve got a factory you’re starting, but you haven’t decided just what your factory is going to make. The products of the factory are undefined: you haven’t decided on their specifics yet, you just know they’re going to be something.
undefined if you haven’t explicitly declared what data type you’re using. As soon as you say your factory makes something specific, like pots or pencils, you define the products, and they are no longer undefined.
Undefined data types can be useful as a placeholder to come back to later in the program, if the value is going to be dependent on other factors. An undefined value is one that doesn’t exist yet.
Null, on the other hand, is a value (sort of), but it’s an empty one. A variable with a value of
null is intentionally devoid of value... and that is its value. Does your head hurt yet? Welcome to programming.
A factory variable with an
undefined value is a factory that doesn’t know (or hasn’t been told) what it’s going to make yet. It might be pencils or candy bars or inflatable unicorn horns for cats. A factory with a value of
null, on the other hand, is one whose interior is a vacuum of nothingness as empty as the void.
Great! Let’s continue.
This can be a scary word when you first start out, but Booleans are extremely simple: they’re either
false. That’s it. Your factory product either is a pencil, or it isn’t.
Booleans (named after mathematician George Boole) can be really handy for checking for values or conditions in your code, and are often used as a kind of switch in the flow of a program. If something is
true, do this; if it’s
false, do something else. This can allow for dynamic operations to trigger in your code depending on if certain conditions are met:
===? That’s called an equality operator. It’s checking that the
factoryOpen variable is
true in the Boolean sense of the value, instead of maybe just representing the word true. More on those pesky equals signs later.
BigInt data type for exceptionally large numbers, but we don't need to cover those yet.
A string can be as small as a single character, or encompass longer text. For text that spans multiple lines, adding a backslash to the end of the line break allows for more text to be stored in the variable.
This works with other data types as well.