We will begin with five data types:
- String
- Integer
- Float
- Boolean
- Array
Strings represent text, and can contain alphanumeric characters and special characters. They are expressed in between quotation marks These are all examples of strings:
- "jimmy"
- "john"
- "make me a sandwhich, please and thank you 2"
Integer and Float are both ways to express numbers. The key difference is that integers are whole numbers while floats can contain decimal points. If an integer or a float is contained withing quotation marks, it is actually a string. The following list contains integers and floats. The integers are on the odd-numbered list line, floats are on even-numbered list lines, but number 5 is neither a float or an integer because it is a string.
- 3
- 3.4
- 4
- 4.5
- "5"
Booleans are the simplest data type because they can only contain one of two possible values, true or false. These are expressed as all lowercase without quotes. Booleans are the on-off switch of programing.
Arrays are a complex data type, which can store collections of other data types between commas. Technically, you can even mix data types within an array. Here are a few examples with each data type in an array.
- [true, true, false, true, false, true]
- [1, 4, 290, 0, 0, 85]
- [3.14, 6.28, 12.56, 25.12]
- ["hi", "hello", "howdy there", "hey", "IT'S SO GOOD TO SEE YOU OMG"]
Data is often expressed as a variable in coding. This means I can creat a large ammount of data and signal it with a single word later on. The syntax looks like var name="value"
. In this case, any time I use the variable name it'll return value as a string output.
Here we'll create a few different variables.
var a = ["apple", "Adam", "Amelia", "auspicious", "alternative"];
var b = "billion";
var e = [8, 18, 1800, 18.8];
Here you'll see that after creating these variables, I can call them back by entering the variable's name alone.