Now that we've looked at how we store data, let's check what we can store!
Things all computers know
In the last video, we said that variables have a name and a type. In this chapter, we'll explore types a bit further. Types define what you can put in a variable. There are different types we can use. You've actually seen one of them already: objects! These are often referred to as complex types because they're complex! As we saw in part one, they contain a lot of information, which is very useful for programming.
Another one is primitive types. As you've seen, they're very concrete and not as complex as some objects can get. The most common types are:
Let's look a little closer at each one.
You learned the term Boolean in the chapter about conditional operations. These logical operations expect to receive a true/false value to make their decision. For example, if you successfully pass this course then you will have a party. 🎈
As you saw previously, the Boolean data type can contain only the values true or false. This is the only data type the computer can use to make decisions. Consider each of the following phrases, each of which produce a Boolean value:
Your age is less than 21.
You have more hair than me.
The temperature is less than 90 degrees AND it's Saturday.
Evaluating each one of these sentences will produce either a true or false response.
The string data type is a series of characters. By characters we mean letters or letter-like symbols used to communicate.
The length of a series of characters, or string, can vary in length. In programming, a string is enclosed in apostrophes or quotations.
The number data type is used for arithmetic operations. Numbers can be positive or negative and may contain a decimal point.
You've already seen this one in the last part! See? You know so much already!
Try it out for yourself!
Classify the following pieces of data according to their primitive data type:
"J Scott Stanlick"
This sentence is not a valid data type. Can you see why?
All computers understand the fundamental primitive data types.
Boolean can be only true or false.
String contains a series of alphanumeric characters.
Number is used in arithmetic.
Null is the presence of nothing.