Basic Data Types and Operations
Numbers and Strings and are the two most fundamental data types.
Numeric data is stored into variables without quotations.
num = 23;
String data simply refers to strings of characters.
String data is stored into variables using quotations. Quotations are required to make the string well-defined. How else could you define the following 5 character string that includes blank spaces on each side of the word?
str = " dog ";
The following variable contains a 4 character string, even though all the characters are numeric.
str = "1234";
The following variable contains a number.
num = 1234;
In the above two cases, the programmer chooses the storage format simply by using quotes or not. But there is much more going on in terms of how strings and numbers are actually stored in computer memory.
Strings are stored as a sequence of character codes (UTF-8/ASCII). For example the string "1234" is stored as 4 bytes (00110001 - 00110010 - 00110011 - 00110100), one for each of the 4 characters. However, the number 1234 is stored as the actual binary equivalent of the number (10011010010). Computers do arithmetic in binary, so the number 1234 needs to be represented as its binary equivalent for calculations. But computers deal with raw data, keyboard input for example, as simply strings of characters. So the string "1234" is simply a sequence of 4 character codes.
In addition to storing data, programmers need perform operations on data such as adding two numbers or joining two strings together. The script in the head section of this document contains examples of common operators that act on strings and numbers. The script below writes those results to this page, but you will have to see the script to understand what all the values mean.