Data Types
Time
1.3 hrs
Difficulty
Beginner
Prerequisites
Variables
Departments
Science
Authors
Sandra Kuipers
Groupings
Individual
Minimum Year Group
None
Blurb
Data comes in many forms: numbers, letters, symbols, and more. This unit looks at primitive data types and how they make up the building blocks of all programming languages.
License
This work is shared under the following license: Creative Commons BY-SA-NC
Outline
Learner Outcomes Students will:
|
|
Competency Focus
|
Interdisciplinary Connections
|
Reflection What was successful? What needs changing? Alternative Assessments and Lesson Ideas? What other Differentiation Ideas/Plans could be used?
|
|
Credits Any CC attribution, thanks, credit, etc.
|
This page requires you to be logged in to access it. Please login and try again.
10 mins
What is Data?
Getting Started
- A computer stores information as data.
- A bindary digit (bit) is the smallest form of data.
- Binary can be used to store 1s and 0s.
- All other types of data start with binary, and are converted into something more meaningful:
5 mins
Types of Data
Theory
- The variables in our code can store many different types of data.
- Chances are, you've already seen and used some data types in your code.
- Some programming languages are loosely typed:
- This means they don't require you to declare a type upfront.
- For example, a
var
in JavaScript can hold any type of data. - We can also combine different types without creating an error.
- In JavaScript, the code
"Hello Cat" + 5;
will create the string"Hello Cat5"
. - Some programming languages are strictly typed:
- This means each variable must be declared with its data type.
- For example, in C#, a
string myVar;
can only hold data that is a string. - Combining variables with different types generally creates an error.
- The following are some of the most common types of data.
5 mins
Boolean
True and False
-
The boolean type has only two values:
true
andfalse
.This type is commonly used to store yes/no values:
true
means “yes, correct”, andfalse
means “no, incorrect”.For instance:
var thisThing = true; var thatThing = false;
- We’ll cover booleans more deeply in the unit on Logical operators.
It helps to remember booleans as a switch: they can only be on or off (true or false)
5 mins
Integer
Numbers
-
An integer is a type of number that does not have a decimal point.
-
A whole number, including negative numbers.
var x = 10; var y = -36;
- There are many operations we can do with numbers, such as multiplication
*
, division/
, addition+
, subtraction-
, and so on.
var score = 42 + 500;
5 mins
Float
Numbers with Decimals
- A float (or floating point number) is a type of number that has a decimal point.
var distance = 4.5; var hours = 1.125;
- To remember Floats vs Integers, I think of them floating on their decimal point like a life-preserver.
5 mins
String
Letters and Symbols
- A string is any number of words, letters and symbols surrounded by quotes:
var question = "What day is it?"; var answer = "Monday";
- Strings can use either 'single quotes' or "double quotes"
var answer1 = "Abolsutely"; var answer2 = 'Not sure'; var answer3 = "It's alright";
It helps to think of them as a bunch of letters, connected on a string:
5 mins
Array
Lists
- Often we need to store a list of things.
- An array is a special variable, which can hold more than one value at a time.
var cars = ["Volvo", "BMW", "Tesla"]; var fibonacci = [0, 1, 1, 2, 3, 5, 8, 13];
- Spaces and line breaks are not important. A declaration can span multiple lines:
var fruit = [ "Apple", "Pear", "Kiwi" ];
- We’ll cover these more in the unit on Arrays.
More Data
Lots more
- There's many more types of data.
- The data types here are often called primitive types.
- This is because they're the basic building-blocks of more complex data.
- Other types of data, like objects, are made up of primitive types.
40 mins
Digital Scavenger Hunt
Evidence
- Take a moment to consider how the above data types might exist in the world around you.
- Your goal is to search for images to help visualize these different data types.
- You may search the web for images.
- You are also welcome to grab your phone and search the school.
- The pictures in this unit are examples, please don't copy them :)
- Open up Google slides and create some slides for this unit.
- Add one slide called Data:
- Include a short definition, in your own words.
- At least one link to a website or video that helps explain this concept.
- Then, add one slide for each of the following data types:
- Boolean
- Integer
- Float
- String
- Array
- For each slide, add:
- A short definition, in your own words.
- An image to help illustrate this concept.
- Once you have finished, submit the link to your slideshow as evidence of learning in this unit.
Images
Embeds
There are no records to display.