1 00:00:01,010 --> 00:00:03,295 Before we go any further with JavaScript, 2 00:00:03,295 --> 00:00:07,530 it's helpful to know that it utilizes different data types. 3 00:00:07,530 --> 00:00:11,783 As you've seen, JavaScript can work with characters surrounded by quotes and 4 00:00:11,783 --> 00:00:13,820 does this using its string data type. 5 00:00:15,070 --> 00:00:20,347 Strings represent sequences of symbols and must be wrapped in quotation marks. 6 00:00:20,347 --> 00:00:24,840 Besides strings, JavaScript also has other data types. 7 00:00:24,840 --> 00:00:26,640 The first we'll discuss are numbers. 8 00:00:27,660 --> 00:00:29,810 These represent real numbers. 9 00:00:29,810 --> 00:00:32,745 We can use them to keep track of scores and counts and 10 00:00:32,745 --> 00:00:35,280 perform mathematical operations on them. 11 00:00:36,760 --> 00:00:38,729 There's also a type called Booleans. 12 00:00:38,729 --> 00:00:41,240 Booleans represent true and false values and 13 00:00:41,240 --> 00:00:44,090 come in handy when a program has to make decisions. 14 00:00:45,490 --> 00:00:50,690 JavaScript has other built in data types and ways to store and keep track of data. 15 00:00:51,750 --> 00:00:54,690 You'll learn all about those in Treehouse's JavaScript courses. 16 00:00:56,310 --> 00:00:58,483 Now that we know about different data types, 17 00:00:58,483 --> 00:01:01,120 let's learn how to use them efficiently in programs. 18 00:01:02,600 --> 00:01:06,880 Storing data to access or update later is a common task in JavaScript. 19 00:01:08,150 --> 00:01:13,180 JavaScript allows us to name and reuse values by storing them in variables. 20 00:01:14,190 --> 00:01:18,580 Think of a variable as a jar with the label indicating what's inside. 21 00:01:18,580 --> 00:01:21,099 At any time, we can look inside the jar, 22 00:01:21,099 --> 00:01:25,440 we can even change what's inside the jar or empty it. 23 00:01:25,440 --> 00:01:28,237 Even though what gets stored in the jar might change, 24 00:01:28,237 --> 00:01:30,920 it's always the same jar with the label we gave it. 25 00:01:32,360 --> 00:01:34,827 Just like we can store something inside a jar, 26 00:01:34,827 --> 00:01:38,380 we can store data inside a JavaScript variable with a unique name. 27 00:01:39,900 --> 00:01:44,160 Whenever we want to access what's inside that variable, we reference its name. 28 00:01:46,050 --> 00:01:48,613 Okay, so from that example, 29 00:01:48,613 --> 00:01:53,137 we know a variable has two parts, a name and a value. 30 00:01:53,137 --> 00:01:57,385 In JavaScript, the syntax for creating a variable 31 00:01:57,385 --> 00:02:02,141 requires beginning with the keyword var, let or const. 32 00:02:02,141 --> 00:02:06,707 Using one of these keywords lets the program know we're preparing to define 33 00:02:06,707 --> 00:02:07,500 a variable. 34 00:02:08,520 --> 00:02:10,430 We'll start by using var in this workshop. 35 00:02:11,570 --> 00:02:15,060 The var keyword is followed by the name we choose for the variable. 36 00:02:16,370 --> 00:02:19,780 We then use the assignment operator or equal sign, 37 00:02:19,780 --> 00:02:23,124 which in JavaScript can be used to assign a value. 38 00:02:23,124 --> 00:02:25,914 Finally, we assign the variable a value, 39 00:02:25,914 --> 00:02:29,410 which can be any of the types I've mentioned or more. 40 00:02:31,250 --> 00:02:35,196 For example, we can name a variable with just a single letter and 41 00:02:35,196 --> 00:02:37,470 set it equal to a value of our choice. 42 00:02:39,190 --> 00:02:41,785 Normally though, we'll want to use a more 43 00:02:41,785 --> 00:02:45,687 descriptive variable name to make our programs more readable. 44 00:02:45,687 --> 00:02:49,030 Let's create a variable to store our favorite foods. 45 00:02:50,290 --> 00:02:53,640 I'll pick mine, but for practice, I want you to choose your own. 46 00:02:55,100 --> 00:02:58,932 First in the console, we'll write the var keyword, 47 00:02:58,932 --> 00:03:02,264 followed by the variable name favoriteFood. 48 00:03:06,360 --> 00:03:09,010 Next we'll use the assignment operator or 49 00:03:09,010 --> 00:03:11,885 equal sign to set the variable equal to sushi. 50 00:03:17,163 --> 00:03:18,824 Now if we press Enter, 51 00:03:18,824 --> 00:03:24,230 then type the variable name favoriteFood again, and press Enter. 52 00:03:24,230 --> 00:03:27,720 The value stored in favoriteFood is printed to the console. 53 00:03:27,720 --> 00:03:28,240 Nice work. 54 00:03:29,360 --> 00:03:31,882 You've learned one of the building blocks of JavaScript. 55 00:03:31,882 --> 00:03:36,622 The most powerful programs rely on variables for storing, 56 00:03:36,622 --> 00:03:39,193 accessing and modifying data. 57 00:03:39,193 --> 00:03:44,310 Next, we'll go further and use JavaScript to operate on values stored in variables.