Why Different Data Types Exist
Different data types exist because the computer has to store and manipulate different types of data in different ways. The computer needs to reserve a lot less space to store the number 4 than it needs for a very long string (this entire book could be one big string). Sometimes different types of data don’t play well together. For example, Listing 5.1 shows how you can add numbers to get numbers, you can add strings to get concatenated strings, and you can add numbers and strings to get ... strings? Getting '22' when you add 2 and '2' is a little nonsensical, but would 4 make any more sense? The difference between the string '2' and the number 2 is very significant to a computer, and confusing them can lead to strange ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access