Skip to content

Instantly share code, notes, and snippets.

@GreysonElkins
Last active March 18, 2020 23:25
Show Gist options
  • Save GreysonElkins/30b96413d223a51d311066c66a8c8b08 to your computer and use it in GitHub Desktop.
Save GreysonElkins/30b96413d223a51d311066c66a8c8b08 to your computer and use it in GitHub Desktop.

A Beginner's Guide to Data Types

by Greyson Elkins

An Introduction to Data

We will begin with five data types:

  • String
  • Integer
  • Float
  • Boolean
  • Array

String

Strings represent text, and can contain alphanumeric characters and special characters. They are expressed in between quotation marks These are all examples of strings:

  1. "jimmy"
  2. "john"
  3. "make me a sandwhich, please and thank you 2"

Integer and Float

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.

  1. 3
  2. 3.4
  3. 4
  4. 4.5
  5. "5"

Boolean

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.

Array

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"]

Using Data in Codes

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.

alt text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment