Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Data Types.docx58.8 KB Data Types - Solution.docx
59 KB
Quick reference
Data Types
Variables hold data. The data is categorized by data type.
When to use
Knowing the type of data something is, makes using variables easier.
Instructions
There are several types of data:
String - words and letters surrounded by quotation marks
Integer - whole numbers
Float - decimal numbers
Boolean - true or false
Arrays - a variable that contains multiple values (more on this in a later lesson)
Object - stores data and information on how to process the data
NULL - nothing
Hints & tips
- Data goes into variables
- There are several data types
- 00:05 In the last video we talked about variables.
- 00:07 In this video, I wanna talk about data types.
- 00:09 When we talked about variables, I said they're like a bucket or a container and
- 00:13 we can put things in them.
- 00:14 But what do we put in them?
- 00:16 We put data in them.
- 00:18 And there are lots of different data types, different types of data.
- 00:21 We're gonna talk about those in this video.
- 00:23 And we used some data types already,
- 00:25 not really knowing what we were doing in the last video.
- 00:27 And we put this variable firstname, we entered in John.
- 00:30 And John is a string, or the data type that John is, is string.
- 00:35 And string is basically just words.
- 00:38 We could easily have put, Hello my name is John.
- 00:43 This is also a string.
- 00:44 It's a string of words.
- 00:46 That's the first data type.
- 00:47 The second data type is something called an integer, 41.
- 00:51 An integer is just a number.
- 00:53 It's a whole number.
- 00:54 Don't confuse it with a decimal, 41.2123.
- 00:57 That's not an integer.
- 00:59 An integer is just a whole number.
- 01:01 And you can see, we did not put quotation marks around this.
- 01:04 You generally don't put quotation marks around numbers.
- 01:07 If you do, it is no longer a number.
- 01:10 This is a string now because we put quotation marks around it.
- 01:13 So that's very sort of interesting, right?
- 01:15 If integers are whole numbers, the next data type is called a float and
- 01:19 a float is decimals.
- 01:21 So 41.12, that's a float.
- 01:23 It's floating point number basically.
- 01:26 Whenever you're using numbers,
- 01:27 it's important to designate whether you're using an integer or a float.
- 01:31 But most of the time you're gonna use a float because how often do you just use
- 01:35 plain integers?
- 01:36 If you're talking about a shopping cart online where people are buying things.
- 01:40 They're buying it with money, something costs $29.95 that's a float.
- 01:44 So the next data type is a boolean.
- 01:47 And boolean is either a true or false, that's what boolean means.
- 01:51 We'll see later on why this is important.
- 01:53 There's a couple of more data types.
- 01:55 One is an array, and we'll talk about arrays a few videos from now.
- 01:58 Arrays are very important in any programming language,
- 02:02 any web development you're gonna be doing, you're gonna be using arrays, probably.
- 02:06 An array is a data type.
- 02:07 An array is just like a variable only with a variable,
- 02:11 you're putting one thing inside of it.
- 02:13 It's a bucket that holds one thing.
- 02:15 An array holds lots of things.
- 02:17 So that's the main difference between the two.
- 02:20 The next data type is something called an object.
- 02:22 That's much more advanced.
- 02:23 We'll talk about that maybe later on.
- 02:26 Finally, the last one is null.
- 02:28 I'ts just N-U-L-L.
- 02:30 And null means nothing, blank absolutely nothing.
- 02:33 In fact, if we type in echo and look as I start to type a variable name F-I-R,
- 02:39 our cloud development tool suggest, it realizes that this is a our variable.
- 02:44 So we don't have to type it all the way out.
- 02:46 You can click on it or
- 02:46 you can just hit the Tab button on your keyboard and that'll work.
- 02:50 So if we save this come back here and reload.
- 02:53 We just have absolutely nothing.
- 02:55 If we view our page source, there's absolutely nothing there.
- 02:58 It's just null, it's just nothing.
- 03:00 So there are certain circumstances where that's important,
- 03:02 we'll get into that later on.
- 03:04 But those are the main data types, strings, integers, floats, booleans,
- 03:08 arrays, and objects, and sometimes null.
- 03:10 In the next video,
- 03:11 we're gonna talk about math and specifically arithmetic operators.
Lesson notes are only available for subscribers.