Skip to content

Instantly share code, notes, and snippets.

@Shawntru
Last active July 16, 2020 00:35
Show Gist options
  • Save Shawntru/18b09df5f213be00b48d941e9fa42562 to your computer and use it in GitHub Desktop.
Save Shawntru/18b09df5f213be00b48d941e9fa42562 to your computer and use it in GitHub Desktop.

Beginner's Guide to Data Types

Guide


String


A string is a data type used represent text. Strings can contain alphabet characters in addition to spaces, numbers, and special characters.

Examples:
  1. "two roads diverged in a yellow wood"
  2. "(303) 731-3117"
  3. "Turing School of Software & Design"

Integers and Floats


Integer: An integer is a whole number (not a fraction) that can be positive, negative, or zero. Unlike floating point numbers, integers cannot have decimal places.

Examples:
  • 10
  • 0
  • -25 Float: As the name implies, floating point numbers are numbers that contain floating decimal points. They can be positive or negative.
Examples:
  • -5.5
  • 0.001
  • 95.2

Boolean


A boolean value is either true or false. Boolean values are used in boolean logic, which is a subset of algebra used for creating true/false statements.

Examples:

true or false

&& || == are operators that assist with boolean logic.


Array


An array is a data structure that represents a group of things.

You can think of an array as a collection, box, or container. Instead of saying "I have a collection of shirts," you could say "I have an array of shirts." The phrase "a container of pencils" would become "an array of pencils."

Typically, elements in an array are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched.

Examples:
[26, 24, 28, 25, 27, 27, 26, 27]
["Mod 0", "Mod 1", "Mod 2", "Mod 3", "Mod 4"]
[false, true, true, true, false, true, true]

Hash/Object


A hash or object is a collection of key-value pairs. It is similar to an array in that it is a collection of things, but in the case of hashes/objects, we are pairing data together.

Sometimes, this data type is referred to as a dictionary because of the pairing of word -> definition.

For example, you might have a hash/object where the keys are first names and the values are last names.

When I think about whether or not I need to use a hash, I ask myself "Is this a collection of data where the pairing of items matters?"

Examples:
  • { "9th grade": 110, "10th grade": 125, "11th grade": 66, "12th grade": 70}
  • { "Mod 0": "Tim and David", "Mod 1": "Mike and Sal", "Mod 2": "Brittany and Robbie" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment