Something to note before we start
If the following seems a bit lengthy for a few definitions, do not let it scare you off, as it is time and words well spend. All to many tutorials, guides and even lectures, jump way too fast over important subjects, in the fear of boring the reader or listener. I do not share that fear, as I believe, that if somebody gets scared away by a few lengthy paragraphs about something important, they are probably not that interested in the subject in the first place, and would surely never have become a good programmer anyway. Programming is about detail and attention to it, and is therefore not for people with a weak attention span and superficial knowledge interests. Programming is for you who want to know why and how, when somebody tells you something.
What we are going to look at
We are going to start from the top and work our way down, ending with Boolean types which will lead us nicely into truthy and falsy values and their pitfalls.
The value undefined has type undefined, and the type undefined represents the primitive value of a variable that has been declared (which is the same as it being initialized) but not yet assigned a value. Now read that again, slowly and let it sink in. This means, that if you declare a variable, which means introducing it into your program by giving it a name (and thereby a space in memory), without assigning it a value (which means storing something in that named memory space) it will get the value undefined. This happens automatically, but of course you can do it manually as well, if you find the need for it. But we will get into that and how exactly to declare a variable and assign it a value, later in this course. If this definition is hard to get your head around, do not worry as we will get back to it and its impact many times later on.
The Number type is the set of all possible Number values, which includes the primitive values NaN (Not-a-Number), positive infinity, and negative infinity. We will look a lot more into how to use these last mentioned primitive values later, and for now it is enough for you to have heard about them.
Truthy and falsy values
The easiest way to get an overview of what evaluates to what, is to list the falsy values and from that conclude that all other values must be truthy, so here they are;
- "" (empty String)
- 0 (the number zero)
I hope that you got something out of what we have been talking about, even though I know that it is a lot of information about something you barely have ventured into yet. I also understand that it can make it all seem like a daunting task to take on, but do not worry, definitions are there to be referenced in the beginning, and only remembered with time. If you have made it through this part, you will do just fine in the coming parts.
Thank you and good luck!